0

I can't figure out the on_message event Everything seems to be correct, there are no errors in the console, but the bot does not respond to messages

import discord
from discord.ext import commands
from discord.ext.commands import Bot
client = commands.Bot(command_prefix='!')

hello_words = ["Hello", "Hi", "qq", "w'zz"]


@client.event
async def on_ready():
    print("Ready") # if the bot running


async def on_message(message):
    msg = message.content.lower()
    if msg in hello_words:
        await message.channel.send("Hello")

client.run("token")

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96

1 Answers1

0

You need to add the client.event decorator to the on_message function. You should also add a check to make sure the bot does not respond to its own messages.

@client.event
async def on_message(message):
    if message.author.bot: 
        return
    msg = message.content.lower()
    if msg in hello_words:
        await message.channel.send("Hello")
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
  • Dont work ;( I have a function with the command event He is working fine ` @client.command(pass_context=True) async def hi(ctx): await ctx.send("Hi!") ` – Dmitriy Makarov Apr 15 '20 at 18:15
  • @DmitriyMakarov See [Why does on_message stop commands from working?](https://stackoverflow.com/questions/49331096/why-does-on-message-stop-commands-from-working) for a solution to that problem – Patrick Haugh Apr 15 '20 at 18:18