【问题标题】:Bot reading other users added reaction机器人阅读其他用户增加了反应
【发布时间】:2020-12-21 05:59:13
【问题描述】:

我做了一个小二十一点游戏,有击中/站立/双打。一切正常,除了机器人读取其他用户的其他附加反应..

  • 如果有人对击打做出反应,而作者对站立做出反应,机器人会先处理击打,然后再处理站立。
  • 如果有人对站立作出反应,而作者对击打作出反应,机器人将处理击打,然后再处理站立。
  • 如果有人对立场作出反应而作者对加倍作出反应,机器人将只处理立场。

这是我的代码:

@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

这是一张照片,其他用户添加了对点击的反应,而作者的信息对站立做出了反应。它发送的是命中而不是支架。

提前致谢。

【问题讨论】:

  • 你能分享完整的命令代码吗?我无法单独使用该代码进行测试。
  • @Lemon.py 编辑并添加图片。
  • 您在异步函数中提供的代码是什么?
  • 是的,在 async 内部再次对其进行了编辑。

标签: python discord.py


【解决方案1】:

通过更改我的 def 检查来修复它。感谢您的回复。

【讨论】:

    猜你喜欢
    • 2019-01-15
    • 2019-12-23
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    • 2019-08-14
    • 2021-07-05
    相关资源
    最近更新 更多