Search code examples
pythondiscordchatbotdiscord.py

Detect Word Then Send Message (discord.py)


I'm trying to simply get my bot to detect the word "wow" when typed and then respond with "oh wow" but I'm not sure how to do it and searching for answers around the internet is not helping me because usually they are not trying to do specifically what I am doing.

This is my code right now

#New Event, prints oh wow if someone says wow
@client.event
async def on_message(message):

    if "wow" in message.content:
        await channel.send("oh wow")

#End of Event

Solution

  • The problem is that you dont define channel. In order to send a message to a channel you first need to define the channel. In this case you want to send a message to the same channel as were the message was send. So you can just use the channel object from the message object.

    Thus you need to do the following:

    @client.event
    async def on_message(message):
    
    if "wow" in message.content:
        await message.channel.send("oh wow")