首页 > 解决方案 > 反应日志显示消息作者的姓名,而不是反应的人(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)

标签: pythondiscord.py

解决方案


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


推荐阅读