0

Issue: When I set up on_message then the sendGif command does not work. When I comment out on_message then it works perfectly.

My Code:

bot = commands.Bot(command_prefix='!')
#----------------------------------------------------------#
@bot.event
async def on_message(message):
if message.author == bot.user:
return
content = message.content
print(content)
if "test" in content:
await message.channel.send("You test" + message.author.mention)
await message.add_reaction(":haha:")
else:
pass
#----------------------------------------------------------#
@bot.command()
async def sendGif(ctx, link):
embed = discord.Embed(title="Embed GIF")
embed.set_thumbnail(url="Gif Link here")
await ctx.send(embed=embed)
PerplexingParadox
  • 1,196
  • 1
  • 7
  • 26
  • 1
    https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working – The Batman BD Apr 14 '21 at 13:19
  • 1
    Does this answer your question? [Why does on\_message stop commands from working?](https://stackoverflow.com/questions/49331096/why-does-on-message-stop-commands-from-working) – Łukasz Kwieciński Apr 14 '21 at 13:22

2 Answers2

0

hi just to the end on_message add

await bot.process_commands (message)

https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working

0

In your on_message event reference, you would have to add the line await bot.process_commands(message). The discord.py documentation explains the process_commands method:

This function processes the commands that have been registered to the bot and other groups. Without this coroutine, none of the commands will be triggered.

By default, this coroutine is called inside the on_message() event. If you choose to override the on_message() event, then you should invoke this coroutine as well.

So, your on_message() event reference should look something like this:

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    content = message.content
    print(content)
    if "test" in content:
        await message.channel.send("You test" + message.author.mention)
        await message.add_reaction(":haha:")
    await bot.process_commands(message)
Jacob Lee
  • 4,405
  • 2
  • 16
  • 37