epik_code
epik_code

Reputation: 17

Python Discord Bot - Reaction Role

How would i make a reaction role event. This is my code i tried with

@client.event
async def on_raw_reaction_add(payload):
    msgID = 05793080854315018
    if payload != None:
        if payload.message_id == msgID:
            if str(payload.emoji) == "✍️":
                await add_roles("cool")

What i wanna do is have my bot checking for reactions on a specific message and then give the user a role if they reacted with the right emoji.

Upvotes: 1

Views: 1338

Answers (1)

DaveStSomeWhere
DaveStSomeWhere

Reputation: 2540

Assuming that you are using discord.py 1.3.3 you can update your code with the following to add a role based on a specific emoji.

You need to add references to the guild in order to reference the role you wish to add. You will also need to compare the emoji to a string representation of payload.emoji. It might be worth considering using emoji.demojize.

Try:

@client.event
async def on_raw_reaction_add(payload=None):
    msgID = <your message id: int>
    guild = discord.utils.get(client.guilds, name=<your guild name>)
    role = discord.utils.get(guild.roles, name='cool')
    if payload is not None:
        if payload.message_id == msgID:
            if str(payload.emoji) == "✍️":
                await payload.member.add_roles(role)

Upvotes: 3

Related Questions