事件结束时命令不起作用

时间:2021-01-14 14:17:16

标签: python python-3.x discord.py discord.py-rewrite

我读到 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)
        

1 个答案:

答案 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)