0

I'm making a discord.py bot, and I want it to send a message when catch a keyword in a sentence or paragraph. I know how to make a keyword command, but I don't know how to make it to determine a keyword inside words, can someone help me this problem? That's my command:

@bot.event
async def on_message(msg):
    if msg.content == 'Good morning' and msg.author != bot.user:
        await msg.channel.send('Good morning boys:)')
bunyaminkirmizi
  • 540
  • 2
  • 6
  • 22
CNWJohn
  • 3
  • 1
  • 1
    Can you clarify the question? What you're saying is that a message can contain a sentence, like say "Hello, good morning everyone", and you want to be able to detect a substring, like say "good morning"? Do you have a problem with the detection, or with actually sending a message? – yaken May 08 '21 at 08:08
  • Nah, I want the command can detect a word in message, like it can find keyword "good Morning in "Hey every one, good morning", and then send a message to reply sender. – CNWJohn May 08 '21 at 09:17

1 Answers1

0

If I understood correctly from your comments, this is the question:

You have a Discord Bot, and you want to detect when there's certain words in a message, like say "Hello World". If a message has "Hello World" in it, then the bot sends a reply.

Here's a small proof-of-concept:

@bot.event 
async def on_message(msg):
  # For more details on how to detect when a string contains a substring in Python, 
  # refer to this question: https://stackoverflow.com/questions/3437059/does-python-have-a-string-contains-substring-method
  if "Hello World" in msg.content and msg.author != bot.user: 
    await msg.channel.send('Good morning boys:)')
yaken
  • 559
  • 4
  • 17