Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(discord.py) Detecting certain keywords in messages

Tags:

discord.py

I was planning to make a grammar bot for fun, and I want it to find certain keywords inside a message, rather than just asking if it is ONLY that keyword. I haven't found anything close to what I want. Help?

like image 373
OffstageAlmond Avatar asked Sep 17 '25 07:09

OffstageAlmond


1 Answers

Assuming you want to check each message that is sent, you can check message.content in the on_message event for the keywords using normal Python. Example code below, where the code will check if FOO is in the message.

@bot.event
async def on_message(message):
    if 'FOO' in message.content:
        print('Keyword found in message')
        # Do stuff here
like image 191
Benjin Avatar answered Sep 23 '25 11:09

Benjin