python - 机器人阅读其他用户增加了反应
问题描述
我做了一个小二十一点游戏,有击中/站立/双打。一切正常,除了机器人读取其他用户的其他附加反应..
- 如果有人对击打有反应,而作者对站立有反应,机器人将先处理击打,然后再处理支架。
- 如果有人对立场作出反应,而作者对击中作出反应,机器人将处理命中,然后它会处理立场。
- 如果有人对立场作出反应,而作者对双倍作出反应,机器人将只处理立场。
这是我的代码:
@commands.command(name='bj')
async def blackjack(self, ctx, bet: int):
hit = ":red_circle:"
stand = ":blue_circle:"
double = ":green_circle:"
msg = await ctx.send('Test')
await msg.add_reaction(HIT)
await msg.add_reaction(STAND)
await msg.add_reaction(DOUBLE)
self.hit = False
self.stand = False
self.double = False
def check(reaction, user):
if str(reaction.emoji) == hit:
self.hit = True
return user == ctx.author and str(reaction.message) == str(msg)
elif str(reaction.emoji) == stand:
self.stand = True
return user == ctx.author and str(reaction.message) == str(msg)
elif str(reaction.emoji) == double:
self.double = True
return user == ctx.author and str(reaction.message) == str(msg)
while True:
try:
reaction = await self.client.wait_for(
"reaction_add", check=check, timeout=20
)
if reaction and hit:
# Do hit things
self.hit = False
await ctx.send('hit clicked')
break
elif reaction and stand:
# Do stand things
self.stand = False
await ctx.send('stand clicked')
break
elif reaction and double:
# Do double things
self.double = False
await ctx.send('double clicked')
break
except asyncio.TimeoutError:
# Do things
await ctx.send('afk')
break
这是它的外观照片,其他用户添加了对击中的反应和作者信息对立场的反应。它发送命中而不是立场。
提前致谢。
解决方案
通过更改我的 def 检查来修复它。感谢您的回复。
推荐阅读
- visual-studio-code - 在 Visual Studio Code ( VS Code ) 中,有没有办法在同一个文档中添加不同颜色的注释?(即针对不同的主题|人)
- r - 错误:包“TStools”的延迟加载失败
- reactjs - Heroku:为什么在 React 应用程序部署后我会收到 H10 错误?
- python - 如何实现 python 代码作为 Azure 函数工作?
- java - 使用多个 JPanel 类时如何在 JFrame 中打开另一个 JPanel
- node.js - Stripe Node.js - 如何在多个受益人(关联账户)之间拆分付款?
- bash - 如果在第二列中有使用 bash 的浮点数,则删除整行
- three.js - Threejs用多个对象更新glb上的单一材料
- r - 创建事件变量的时间和时间
- methods - 我如何为这个 Rust 特征使用相同的默认实现