Skip to content Skip to sidebar Skip to footer

How To Make Give Role On_message In Discord.py?

I want the bot to give role to users if they mentions three people in a specific channel , I want to do this with 2 channels and role for both channels are different, code: @client

Solution 1:

Your error i think is with the emoji itself make sure it is in the guild i edited it a bit.

@bot.event
async def on_message(message):
    if message.channel.id == 724969989777522778 or message.channel.id == 724970270347100203:

        if len(message.mentions) >= 3:
            role_name = "CUSTOM 3pm" if message.channel.id == 724969989777522778 else "CUSTOM 4pm"
            await message.add_reaction(emoji='✅')
            role = discord.utils.get(message.guild.roles, name=role_name)
            user = message.author
            try:
                await user.add_roles(role)
            except:
                print('Already have the role')

    await bot.process_commands(message)

Post a Comment for "How To Make Give Role On_message In Discord.py?"