Search code examples
pythondiscorddiscord.py

disnake bot user.add_role results in 403 despite admin permissons


With my disnake bot I'm trying to add a role to a user. I am getting the following error:

File "/code/cogs/whitelist.py", line 298, in adduser
     await user.add_roles(role)
File "/usr/local/lib/python3.8/site-packages/disnake/member.py", line 997, in add_roles
     await req(guild_id, user_id, role.id, reason=reason)
File "/usr/local/lib/python3.8/site-packages/disnake/http.py", line 436, in request
     raise Forbidden(response, data)
disnake.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

More info:

  • the bot has admin permissions
  • I'm using a slash command here. The bot has application command permissions.
  • I'm trying to add a non-admin role
  • I'm trying to add the role to a non-admin user

I'm adding the bot with the following permissions:

permissions=8&scope=bot%20applications.commands

Any idea why I'm getting permission denied?


Solution

  • The problem is mostly due by the fact that not only Discord roles can be administrators, but they also have an order.

    Your bot can't assign roles higher than its highest one, so probably that role is higher than the role that makes your bot administrator.

    You just have to provide it an higher role, maybe the higher in the guild.


    The order of the roles is given by the following menu.

    In this case ElFrost is the highest role.