Discord.py: member.add_roles() can't find role

Created on 18 Aug 2019  路  3Comments  路  Source: Rapptz/discord.py

Summary

I am currently trying to assign a role to a member with a specific given ID. I can request the role by using discord.utils.get(), yet when I hand it over to Member.add_roles(), it's not able to assign the Role. In fact, it tells me this role does not exist.

Reproduction Steps

```Python

printing this_member returns

this_member = ctx.message.author

printing this_guild returns

this_guild = this_member.guild

printing this_role returns

this_role = get(this_guild.roles, id=int(role_id))

returns None and causes this Exception:

404 NOT FOUND (error code: 10011): Unknown Role

await this_member.add_roles(this_member, this_role)

Expected Results

The expected result would be a role assignment with the specified role to the member. Since it can be found using discord.utils.get()

Actual Results

404 NOT FOUND: Unknown Role exception gets thrown.

Ignoring exception in command setroles:
Traceback (most recent call last):
File "/home/mtrx/Git/bikehaven/venv/lib/python3.6/site-packages/discord/ext/commands/core.py", line 79, in wrapped
ret = await coro(args, *kwargs)
File "src/bot.py", line 40, in setroles
await this_member.add_roles(this_member, this_role)
File "/home/mtrx/Git/bikehaven/venv/lib/python3.6/site-packages/discord/member.py", line 616, in add_roles
await req(guild_id, user_id, role.id, reason=reason)
File "/home/mtrx/Git/bikehaven/venv/lib/python3.6/site-packages/discord/http.py", line 220, in request
raise NotFound(r, data)
discord.errors.NotFound: 404 NOT FOUND (error code: 10011): Unknown Role

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/mtrx/Git/bikehaven/venv/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 863, in invoke
await ctx.command.invoke(ctx)
File "/home/mtrx/Git/bikehaven/venv/lib/python3.6/site-packages/discord/ext/commands/core.py", line 728, in invoke
await injected(ctx.args, *ctx.kwargs)
File "/home/mtrx/Git/bikehaven/venv/lib/python3.6/site-packages/discord/ext/commands/core.py", line 88, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 NOT FOUND (error code: 10011): Unknown Role

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

System Information

位 python -m discord -v

  • Python v3.6.9-final
  • discord.py v1.1.1-final
  • aiohttp v3.5.4
  • websockets v7.0
  • system info: Linux 5.1.21_1 #1 SMP PREEMPT Sun Jul 28 20:09:28 UTC 2019

Most helpful comment

changing:
await this_member.add_roles(this_member, this_role)
to
await this_member.add_roles(this_role)
fixed it.

All 3 comments

As per the docs: https://discordpy.readthedocs.io/en/latest/api.html#discord.Member.add_roles

add_roles does not take a member obj as an argument because it is already a method of that obj.

You are getting this error because you are trying to add a member obj as a role.

For more questions like this feel free to join the support server.

Setting it by role ID doesn't work either. I've tried both, same error. I'll join the support server and write a follow up should I be able to fix it

changing:
await this_member.add_roles(this_member, this_role)
to
await this_member.add_roles(this_role)
fixed it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x78f1935 picture 0x78f1935  路  20Comments

VoxelPrismatic picture VoxelPrismatic  路  16Comments

pappabewar picture pappabewar  路  26Comments

Yuvira picture Yuvira  路  18Comments

wolfclaws picture wolfclaws  路  17Comments