问题
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)
回答1:
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:
- Bot.process_commands()
- on_message()
来源:https://stackoverflow.com/questions/62076257/discord-py-bot-event