反应日志显示消息作者的姓名而不是反应的人(discord.py)

时间:2021-03-18 08:23:59

标签: python discord.py

我正在 discord.py 中开发一个机器人,我正在尝试在我的机器人日志中创建一个反应日志,但它没有说做出反应的人,而是说消息作者。有人可以帮我吗?

这是我的代码:

@client.event
async def on_reaction_add(reaction, user):
    message = reaction.message
    channel = message.guild.get_channel(812838695169949727)
    embed=discord.Embed(title="{} added a reaction!".format(message.author.name), description="", color=0xffa500)
    embed.add_field(name="This is the channel:", value=str(message.channel), inline=False)
    embed.add_field(name="This is the message:", value=message.content, inline=True)
    embed.add_field(name="This is the reaction:", value=str(reaction), inline=True)

    await channel.send(embed=embed)

1 个答案:

答案 0 :(得分:2)

reaction.message.author 是消息的原始作者。做出反应的用户是 user 事件处理程序的 on_reaction_add 参数,因此要获取他们的名字,您应该在第 5 行使用 user.name 而不是 message.author.name

相关问题