I want to specify that the variable "role" is a role that I created named 'testcom'. So that when i call it in user.add_roles, it will give the user the specified role. Any help? Thank you.
@client.command(pass_context=True)
async def testcom(ctx, user: discord.Member):
role = ##help here ##
await user.add_roles(role)
await ctx.send("done")
CodePudding user response:
role = discord.utils.get(guild.roles,name="name_of_the_role_you_need")
This way role
is a variable that contains a discord.Role
object.
You can also get the role by int
id:
role = ctx.guild.get_role(0238023802302) # put your id
I would suggest you to read the content of this gist too.
CodePudding user response:
You need to access the role id from the guild:
@client.command(pass_context=True)
async def testcom(ctx, user: discord.Member):
role = ctx.guild.get_role(role int here)
await user.add_roles(role)
await ctx.send("done")