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.
```Python
this_member = ctx.message.author
this_guild = this_member.guild
this_role = get(this_guild.roles, id=int(role_id))
await this_member.add_roles(this_member, this_role)
The expected result would be a role assignment with the specified role to the member. Since it can be found using discord.utils.get()
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
位 python -m discord -v
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.
Most helpful comment
changing:
await this_member.add_roles(this_member, this_role)to
await this_member.add_roles(this_role)fixed it.