python - 你是怎么做到的,所以 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]”。
解决方案
reaction.message.author
是一个对象,但是当它转换为字符串时,它会作为用户名输出。尝试if reaction.message.author.id == client.user.id
改用。
推荐阅读
- antd - 特定容器中的模态弹出窗口而不是根目录
- java - 从数据库显示到谷歌日历的事件
- git - 使用 git worktree 时如何忽略 .gitignore?
- html - 解析 NodeJS/Express 中的相对路径
- selenium - 如何解决硒网格中的 FORWARDING_TO_NODE_FAILED 问题
- asp.net - 使用 MsDeploy 在 Docker 上发布 ASP.Net 站点
- javascript - 将 const 项复制到数组
- c# - LINQ count issue on an observable collection
- sql - 替换 hive 中的空字符串 - Nvl 和 COALESCE 已尝试
- python - 从一个给定条件创建不同的数据框