Robin Long
Robin Long

Reputation: 11

How to create reaction role with discord.py?

I am making a reaction role system, but when I react with the emoji I put, it does nothing. The code is here:

@bot.event
async def on_raw_reaction_add(payload):
    message_id = payload.message_id
    if message_id == 757982178691776635:
        guild_id = payload.guild_id
        guild = bot.get_guild(guild_id)
        if payload.emoji.name == 'white_check_mark':
            print('Role')

I get no error in console and it does not print Role in console.

Upvotes: 0

Views: 217

Answers (2)

Abdulaziz
Abdulaziz

Reputation: 3426

You can get the emoji charcter from here and then compare it.

I made it a little bit shorter for ease of read.

@bot.event
async def on_raw_reaction_add(payload):
    if payload.message_id == 757982178691776635:
        guild = bot.get_guild(payload.guild_id)
        if payload.emoji.name == '✅':
            print('Role')

Upvotes: 0

unex
unex

Reputation: 1356

Try printing the value of payload.emoji.name, it is going to be the emoji itself usually. If you want to match based on the unicode name, I suggest using unicodedata.name

Upvotes: 1

Related Questions