Discord.py@bot.event

2024-09-27 22:32:12 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一个脚本,它同时使用@bot.event@bot.command()。问题是当我有一个@bot.event在等待时@bot.command()将不会运行

这是我的密码:

@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)

Tags: eventsendmessageasynciftimeondef
1条回答
网友
1楼 · 发布于 2024-09-27 22:32:12

on_message事件与命令混合使用时,您需要添加await bot.process_commands(message),如下所示:

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

如文件所述:

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.


参考文献:

相关问题 更多 >

    热门问题