我读到 on_message
事件如何需要在最后有 await bot.process_commands(message)
以便它可以在之后运行命令,但它对我不起作用。你知道为什么它不起作用吗?
@client.event
async def on_message(message):
print(message.author.id)
if message.author.id == <user_id>:
await message.add_reaction("❤️")
else:
return
await bot.process_commands(message)
答案 0 :(得分:1)
您在处理命令之前有一个 return
语句,它没有到达该行。
最重要的是,您在 await bot.process_commands(message)
语句中放置了 else
,它忽略了对其余代码的命令的处理。
正确的代码应该是这样的:
@client.event
async def on_message(message):
print(message.author.id)
if message.author.id == <user_id>:
await message.add_reaction("❤️")
else:
return
await bot.process_commands(message)