Bug related to an add role command on discord.py

Advertisements

I have this command I made with a Discord bot in Python. Basically, it’s an event where it gives you a "Saloon Member" role when you write "givemembership" this command has been working on some of my test servers but sometimes simply didn’t.(I always gave the bot the admin perms.)When it didn’t work, the logs of the bot were saying the following :
enter image description here
Could someone maybe explain to me why it is not working ?
Here’s the command programm.

@bot.event
async def on_message(message):
    if message.content == "givemembership":
        member = message.author
        role = get(member.guild.roles, name="Saloon Member")
        await member.add_roles(role)

>Solution :

The Forbidden error implies the bot doesn’t have permissions – so I would make sure that the bot’s role (or a role that the bot has) is always above the role you want it to be able to assign. Otherwise it won’t have the necessary perms.

Leave a Reply Cancel reply