首页 > 解决方案 > 您如何检查特定用户是否对带有许多特定表情符号的特定消息做出反应

问题描述

我目前正在制作汽车经济机器人,我希望能够像游戏一样与机器人互动。我想对按钮使用反应,但问题是当我使用代码时,

confirm_right = await client.wait_for("reaction_add", check=react_check_right) 
confirm_left = await client.wait_for("reaction_add", check=react_check_left) 

它没有按预期工作,首先它等待confirm_right,然后是confirm_left。

我希望能找到一种方法让它们同时工作。

这是我的检查功能,

def check(message):
        return ctx.author.id == message.author.id

    def react_check_right(reaction, user):
        return user == ctx.author and str(reaction.emoji) in ["➡️"]

标签: pythondiscorddiscord.py

解决方案


找到了答案

reaction, user = await client.wait_for('reaction_add', check = lambda reaction, user: reaction.emoji in ["➡️", "⬅️"])

        if user == ctx.author:
            if reaction.emoji == '➡️':
                if car_shown < len(users[str(user.id)]['car']) - 1:
                    car_shown += 1
                else:
                    car_shown = 0
    ```
this was basically it


推荐阅读