首页 > 解决方案 > 机器人阅读其他用户增加了反应

问题描述

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

这是我的代码:

@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

这是它的外观照片,其他用户添加了对击中的反应和作者信息对立场的反应。它发送命中而不是立场。

提前致谢。

标签: pythondiscord.py

解决方案


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


推荐阅读