2

Whenever i add an event, it disables all my commands, why does it do this? This is my code that i have so far. Is it because i have ctx AND message written and they just dont work together or what? This is not all of my code, this is only the part where im having trouble. Any help would be appreciated. Thanks!


@bot.event
async def on_message(message):
    if message.author.id == bot.user.id:
        return
    msg_content = message.content.lower()

    curseWord = ['badword', 'badword2']
    
    if any(word in msg_content for word in curseWord):
      await message.delete()
      embed=discord.Embed(title="No No Word", description="Hey! Those words arent allowed here!", color=0x00FFFF)
      await message.channel.send(embed=embed)

keep_alive()

bot.run(os.getenv('TOKEN'))                        
ColeTMK
  • 96
  • 1
  • 10

2 Answers2

2

Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message. For example:

@bot.event 
async def on_message(message):
    # do some extra stuff here

    await bot.process_commands(message)

Reference

buga
  • 367
  • 2
  • 15
1

Luckily I worked out this command myself today and one seeing it I got the issue.

When this on_message was called by you yourself whereas usually it is called by this couroutine itself. So as you called it yourself you need to do it again.

You need to add this statement:

await bot.process_commands(message)

I changed the code in accordance to your code and hope this helps.

@bot.event
async def on_message(message):
    if message.author.id == bot.user.id:
        return
    msg_content = message.content.lower()

    curseWord = ['badword', 'badword2']
    
    if any(word in msg_content for word in curseWord):
      await message.delete()
      embed=discord.Embed(title="No No Word", description="Hey! Those words arent allowed here!", color=0x00FFFF)
      await message.channel.send(embed=embed)
    else:
      await bot.process_commands(message)

keep_alive()

bot.run(os.getenv('TOKEN')) 

This would work for you. :)

Thank You! :D

Bhavyadeep Yadav
  • 819
  • 8
  • 25