gpt4 book ai didi

python - Discord.py @bot.event

转载 作者:行者123 更新时间:2023-12-05 02:53:41 24 4
gpt4 key购买 nike

所以我有一个同时使用 @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)

最佳答案

当混合使用 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.


引用资料:

关于python - Discord.py @bot.event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62076257/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com