事件结束时命令不起作用
commands not working when event is over it
我读到 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)
您在处理命令之前有一个 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)
await bot.process_commands(message)
必须是 client.process_commands(message)
,因为这是您在 client = commands.Bot()
.
中定义的机器人实例
我读到 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)
您在处理命令之前有一个 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)
await bot.process_commands(message)
必须是 client.process_commands(message)
,因为这是您在 client = commands.Bot()
.