您如何做到这一点,以便on_reaction_add仅在响应机器人消息时触发

时间:2020-09-08 23:56:30

标签: python discord discord.py

这是我现在拥有的代码:

# 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]”。

1 个答案:

答案 0 :(得分:0)

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