Mika Tan
Mika Tan

Reputation: 128

(Discord.py) How do I make a command that gives you a role that's specified?

I'm trying to code a command in discord.py that when called, will give you a role called "DJ"

Here's my current code:

@client.command
async def role(ctx):
    user = ctx.message.author
    role = discord.utils.get(user.server.roles, name="DJ")
    await client.add_roles(user, role)

It is also worth noting that this bot is in 2 servers, one of which does not have the DJ role in the server. Is that a problem?

Thank you

Upvotes: 0

Views: 126

Answers (1)

Ethan M-H
Ethan M-H

Reputation: 600

You should be able to do something similar to

@client.command()
async def role(ctx, *, role: discord.Role):
   await ctx.author.add_roles(role)

Upvotes: 1

Related Questions