【问题标题】:Make a bot respond to reactions to a specific message - discord.py让机器人响应对特定消息的反应 - discord.py
【发布时间】:2021-11-28 07:14:20
【问题描述】:

我开始改造我的 mod-mail 机器人,并希望让用户选择他们想要联系的服务器。由于有 2 个服务器,机器人的反应有 2 个反应,并且根据用户的反应,它会联系该服务器。

但是我遇到了一个问题。当试图这样做时。我找不到类似 if else 功能的方法,如果用户对添加的其中一个反应做出反应,它会联系该服务器。

我怎样才能做到这一点,如果用户对绿色反应做出反应,机器人会做其他事情而不是用户对红色反应做出反应。

这是我的代码:

def green_check(reaction, user):
        return str(reaction.emoji) == '????' and user != bot.user

    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=3600.0, check=green_check)
    except asyncio.TimeoutError:
        await concept_msg.delete()
        await ctx.author.send("No moderator responded, wait some time and try again.")
        return
    else:
        concept_embed_dict = concept_embed.to_dict()
  

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    在您的检查中,您可以查看表情符号是否是您想要的两件事之一,然后再检查它是哪一个并执行您想要的代码。
    大概是这样的吧?

    def green_check(reaction, user):
        return str(reaction.emoji) in ['?', '?'] and user != bot.user
    
    try:
        reaction, user = await bot.wait_for('reaction_add', timeout=3600.0, check=green_check)
    except asyncio.TimeoutError:
        await concept_msg.delete()
        await ctx.author.send("No moderator responded, wait some time and try again.")
        return
    else:
        if str(reaction.emoji) == '?':
            #do something
        elif str(reaction.emoji) == '?':
            #do something else
        else:
            pass
    

    【讨论】:

      猜你喜欢
      • 2020-11-07
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 2020-09-08
      • 1970-01-01
      • 2022-12-07
      • 1970-01-01
      相关资源
      最近更新 更多