如何让机器人对**只有一个**特定的表情符号做出反应?

时间:2021-06-25 20:10:35

标签: python discord bots

我是一个绝对的初学者,只是提一下。所以机器人应该理解(显示为消息“ThumbUp/ThumbDown”)用户已经对已经存在的反应做出反应。我的问题是,如果我对两种反应之一做出反应,两条消息都会发出,所以我想我需要以某种方式将它们分开。任何人都可以帮助我吗?

  @client.event
        async def on_reaction_add(reaction, user):

            reaction == get(message.reactions, emoji='?')
            if reaction.count > 1:
                    await message.channel.send('ThumbUp')
                    await helpmessage.delete()
            else:
                    await asyncio.sleep(30)
                    await helpmessage.delete()

            reaction == get(message.reactions, emoji='?')
            if reaction.count > 1:
                    await message.channel.send('ThumbDown')
                    await helpmessage.delete()
            else:
                    await asyncio.sleep(30)
                    await helpmessage.delete()

2 个答案:

答案 0 :(得分:0)

有几种方法:

  1. 使用其他:
@client.event
async def on_reaction_add(reaction, user):
    reaction = get(message.reactions, emoji='?')
    if reaction.count > 1:
        await message.channel.send('ThumbUp')
    else:
        reaction = get(message.reactions, emoji='?')
        if reaction.count > 1:
            await message.channel.send('ThumbDown')
        else:
            await asyncio.sleep(30)

    await helpmessage.delete()
  1. 使用字典:
@client.event
async def on_reaction_add(reaction, user):
    checks = {'?': 'ThumbUp', '?': 'ThumbDown'}
    for emoji, msg in checks.items():
        reaction = get(message.reactions, emoji=emoji)
        if reaction.count > 1:
            await message.channel.send(msg)
            break
    else:
        await asyncio.sleep(30)

    await helpmessage.delete()

答案 1 :(得分:0)

似乎修复是在行中添加第二个 =,其中 reaction 被确定。所以它是 reaction == get(helpmessage.reactions, emoji="?")