首页 > 解决方案 > 你是怎么做到的,所以 on_reaction_add 只在机器人的消息被反应时触发

问题描述

这是我现在的代码:

# Reaction events
@client.event
async def on_reaction_add(reaction, user):
    if reaction.message.author == "Among Us Bot#3079":
        emoji = reaction.emoji
        if user.bot:
            return
        if emoji == '✅':
            fixed_channel = client.get_channel(742888039872856067) # General / main chat channel ID
            await fixed_channel.send(f'{user.mention} is ready to play! [{reaction.count - 1}/10]')
    else:
        print("BRUH")


@client.event
async def on_reaction_remove(reaction, user):
    if reaction.message.author == "Among Us Bot#3079":
        emoji = reaction.emoji
        if user.bot:
            return
        if emoji == '✅':
            fixed_channel = client.get_channel(742888039872856067) # General / main chat channel ID
            await fixed_channel.send(f'{user.mention} is no longer ready to play! [{reaction.count - 1}/10]')
    else:
        print("BRUH x2")

现在,当您通过检查对任何消息做出反应时,它会将“BRUH”打印到控制台中。在if reaction.message.author == "Among Us Bot#3079":任何消息是否有检查反应之前,它会说“{user} 准备好播放![0/10]”。

标签: pythondiscorddiscord.py

解决方案


reaction.message.author是一个对象,但是当它转换为字符串时,它会作为用户名输出。尝试if reaction.message.author.id == client.user.id改用。


推荐阅读