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)
解决方案
reaction.message.author
是邮件的原作者。做出反应的用户是事件处理程序的user
参数on_reaction_add
,因此要获取他们的名称,您应该使用user.name
而不是message.author.name
在第 5 行。
推荐阅读
- javascript - 如何使用js获取会话的值
- gojs - 从 Go js 中的 License Certificate No 中查找许可证密钥
- javascript - 多个 setTimeout:并行还是递归?
- arrays - var 和 := 在 slice 声明 go 语言中的区别
- html - Angular6根据构建配置更改站点日志
- php - 如何知道本地托管的 php 脚本加载时间
- python - Python argparse:传递没有参数名称的单个参数
- asp.net-core - Razor Pages 中 @page 指令中的强类型路由
- python - 我已经分配了我的变量,但输出显示:“分配前引用的局部变量”
- c++ - tensorflow C++ 相当于 tf.trainable_variables()?