Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the add_roles method from the python discord api

So I've been trying to figured out how to use the add_roles() method but I run into the issue of not being able to find out how to obtain a specific role object and also was wondering if the member argument was suppose to be a user ID# or the users name. I'm new to this whole thing so an explanation with an example would be a preferred means of response if possible.

like image 204
Smithy Avatar asked Nov 29 '25 06:11

Smithy


1 Answers

When using add_roles() you should pass in a member object. To obtain a specific role object you should use the discord.utils.get() function.

In the example below we are first retrieving the role. Note how we need an instance of the server to do this. Also note that the this is an attribute search so name could be, for example id, or even both. See the documentation for more information. Next we are using the add_roles() function passing in, first the member object and then the role we just retrieved.

Example:

role = discord.utils.get(server.roles, name="admin")
await client.add_roles(member, role)

If you are having problems with discord.py I would recommend reading the documentation and/or reading through the code of other bots using discord.py on GitHub.

like image 60
mooster311 Avatar answered Nov 30 '25 20:11

mooster311