Ahmed Adel
Ahmed Adel

Reputation: 933

how to make command for specific role on discord.py

I Want to check if the message author has admin role to use this command or not in my case it always gives me False and i know the code is not right

 @client.command(pass_content=True)
    async def new(ctx, member:discord.Member, nick):
        role = author.get_role(name="Admin")
        if role in author.roles:
            await member.edit(nick=nick)
            await ctx.send(f"Nickname changed")

Upvotes: 0

Views: 1065

Answers (2)

mcdonalds291
mcdonalds291

Reputation: 2394

You can use @commands.has_role(role ID or name)

For a role ID:

@bot.command()
@commands.has_role(123123)
async def test(ctx):
   await ctx.send('It works!')

For a role name:

@bot.command()
@commands.has_role("role_name")
async def test(ctx):
   await ctx.send('It works!')

I highly recommend using a role id because role names aren't unique.

Upvotes: 1

ArtyTheDev
ArtyTheDev

Reputation: 36

You can use @commands.has_role("rolename") the in your @client.command

like this

@client.command(pass_content=True)
@commands.has_role("mod")
async def name(parameters):
   #your code

Upvotes: 1

Related Questions