techNOlogics
techNOlogics

Reputation: 33

Discord.py @bot.event

So I have a script that uses both @bot.event and @bot.command(). The problem is that when I have a @bot.event waiting the @bot.command() will not run.

Here is my code:

@bot.event
async def on_ready():
    print("Bot Is Ready And Online!")
    
async def react(message): 
    if message.content == "Meeting":
        await message.add_reaction("👍")

@bot.command()
async def info(ctx):
    await ctx.send("Hello, thanks for testing out our bot. ~ techNOlogics")

@bot.command(pass_context=True)
async def meet(ctx,time):
    if ctx.message.author.name == "techNOlogics":
        await ctx.channel.purge(limit=1)
        await ctx.send("**Meeting at " + time + " today!** React if you read.")

@bot.event ##THIS ONE HOLDS UP THE WHOLE SCRIPT
async def on_message(message):
    await react(message)

Upvotes: 3

Views: 16359

Answers (1)

Diggy.
Diggy.

Reputation: 6944

When using a mixture of the on_message event with commands, you'll want to add await bot.process_commands(message), like so:

@bot.event
async def on_message(message):
    await bot.process_commands(message)
    # rest of code

As said in the docs:

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.

If you choose to override the on_message() event, you then you should invoke this coroutine as well.


References:

Upvotes: 6

Related Questions