python - Discord.py - 在有人第一次做出反应后检查反应
问题描述
vote_msg = await ctx.send(embed=embed)
await vote_msg.add_reaction('✅')
await vote_msg.add_reaction('❎')
reaction, member = await ctx.bot.wait_for('reaction_add')
vote_msg = await vote_msg.channel.fetch_message(vote_msg.id) # refetch message
# default values
positive = 0
negative = 0
for reaction in vote_msg.reactions:
if reaction.emoji == '✅':
positive = reaction.count - 1
elif reaction.emoji == '❎':
negative = reaction.count - 1
print(positive)
print(negative)
目前我有这个来重新获取对消息的反应,我怎样才能让它在有人第一次反应后重新获取它,而不是让它等待 5 秒并检查?
解决方案
我认为您正在寻找on_reaction 侦听器
您可以从 react.message.reactions 访问所有消息反应,如下所示:
@bot.event
async def on_reaction_add(reaction, user):
reactions = reaction.message.reactions
# DO WHAT YOU WANT HERE
推荐阅读
- php - sudo 的行为与正常的脚本执行不同
- java - 如何在 Spring Boot 中创建一个在运行时返回整数的 SQL 查询?
- ios - iOS 模拟器无法读取我保存的健康数据
- android - 在 React Native View 中显示 Android Native Activity
- lets-encrypt - 让加密证书导致 Avast 出现问题?
- python - 如何检查单元检查中的错误?
- javascript - 将所有表导出到单个 csv
- javascript - 请求 API 并等待答复
- html - 当键盘以模态关闭按钮打开时不起作用(Ionic 5)
- firebase-authentication - Google Identity Platform 是否有本地模拟器?