3

I'm trying to make a selection screen with two options (two reactions) which the user can react to, and the bot will now what reaction did the user chose

I've tried comparing
reaction != "๐Ÿ‘Œ" or reaction != "โœ‹" Also tried: reaction != u"\U0001F44C" or reaction != u"\u270B" using the unicode. Also tried the same code with reaction.emoji, str(reaction / reaction.emoji). Also tried comparing the id of the emojis but reaction.emoji.id raise an exception saying that reaction.emoji is a str and strings doesn't have id (because idk why it returns a str instead of a emoji object) I've read the docs and it says it supports != operations but I don't know what to compare

@bot.event
async def on_reaction_add(reaction,user):
     print(reaction) #It prints the two emojis on my console (๐Ÿ‘Œ and โœ‹)
     if user.bot:
        print('I am a bot')
        return
     if reaction != "๐Ÿ‘Œ" or reaction != "โœ‹":
        print('Did not found the emoji')
        return
     else:
        print('Found the emoji')
#And then some code which will decide if the user that reacted is valid and what to do with it
    

#The embed the user have to react to if this helps
embed = discord.Embed(title = 'VS',color=0x00fff5)
        embed.set_author(name = message.author.name,icon_url=message.author.avatar_url)
        embed.set_footer(text = message.mentions[0].name , icon_url = mensaje.mentions[0].avatar_url)
        response = await message.channel.send(embed = embed)
        await response.add_reaction("๐Ÿ‘Œ") #OK emoji
        await response.add_reaction("โœ‹") #STOP emoji

I expect the bot to recognize the emojis but don't know how.

2
  • The docs here definitely suggest it is str(reaction.emoji) == '๐Ÿ‘' as you tried. I am wondering if this line if str(reaction.emoji) != "๐Ÿ‘Œ" or str(reaction.emoji) != "โœ‹": can ever evaluate to False though. Could you try something simpler like if str(reaction.emoji) == "๐Ÿ‘Œ": print("OK reaction found")
    – kcontr
    Jul 9, 2019 at 16:59
  • 1
    You should almost certainly be using Client.wait_for instead of on_reaction_add Jul 9, 2019 at 17:59

1 Answer 1

1

TL;DR

  1. switch or for and
  2. use str(reaction.emoji) (see example in the discordpy docs)

Explanation:

De Morgan's Laws would say that

if str(reaction.emoji) != "๐Ÿ‘Œ" or str(reaction.emoji) != "โœ‹":

is the same as writing

if not (str(reaction.emoji) ==  "๐Ÿ‘Œ" and str(reaction.emoji) == "โœ‹"):

and since the reaction cannot be both an OK and a STOP at the same time, that if statement always comes back True and "Did not find the emoji" is always printed.

Something like

     if str(reaction.emoji) != "๐Ÿ‘Œ" and str(reaction.emoji) != "โœ‹":
        print('Did not found the emoji')
        return
     else:
        print('Found the emoji')

would work.

EDIT: A slightly more readable solution IMHO would be to check for the presence of the emoji in a set.

     if str(reaction.emoji) not in { "๐Ÿ‘Œ", "โœ‹"}:
        print('Did not find the emoji')
        return
     else:
        print('Found the emoji')

Your Answer

By clicking โ€œPost Your Answerโ€, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.