D
D
darud2021-10-14 11:28:24
Python
darud, 2021-10-14 11:28:24

How to make it so that when a person removes the reaction, the role is taken away?

@client.event
async def on_raw_reaction_add(payload):
    channel = client.get_channel(payload.channel_id)
    message = await channel.fetch_message(payload.message_id)
    guild = client.get_guild(payload.guild_id)
    reaction = discord.utils.get(message.reactions, emoji=payload.emoji.name)

    # only work if it is the client
    if payload.member.id == client.user.id:
        return

    if payload.message_id == 898092846287028225 and reaction.emoji == '✅':
        role = discord.utils.get(guild.roles, name='LASTTASK')
        await payload.member.add_roles(role)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yanis07, 2021-10-15
@Yanis07

@client.event
async def on_raw_reaction_remove(payload):
    if payload.message_id in roles_assignment_setup['massage_id']:
        if payload.emoji.name in roles_assignment_setup["emoji_to_role"]:
            guild = client.get_guild(payload.guild_id)
            member_remove_role = await guild.fetch_member(payload.user_id)
            role = discord.utils.get(guild.roles,
                                     id=roles_assignment_setup["emoji_to_role"][payload.emoji.name])
            await member_remove_role.remove_roles(role)
            log.info(f"Role was removed {member_remove_role} - {role}")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question