1
votes

So I want the bot to auto assign roles when a user has reacted to a message with a specific emoji. But my code does not work. How can I fix this????

@client.event 
async def on_raw_reaction_add(payload):
    messgae_id = payload.message_id
    if messgae_id == "759765065380659261":
        user = payload.user_id
        for roles in user.roles:
            if roles in DefaultRoles:
                return
        if payload.emoji.name == "smiling_imp":
            role = discord.utils.get(user.server.roles, name = "Demon")
            await user.add_role(user, role)
1

1 Answers

0
votes

For the standard discord emojis, you can't use the name, you need to use the unicode symbol. So not 'smiling_imp' but '😈'

To get unicode emojis you can add \ before the standard emoji before sending it (don't think it works on mobile)

After Discord.py 1.0, "server" is changed to "guild"


    if message_id == ________________: 

        # Find the guild name
        guild_id = payload.guild_id
        guild = discord.utils.find(lambda g :g.id == guild_id, client.guilds)

        # Get your guild role
        if payload.emoji.name == '😈':
            role = discord.utils.get(guild.roles, name='Demon')

        # Find the member you are trying to assign role to
        member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)

        # Assign role
        await member.add_roles(role)