samuelom
samuelom

Reputation: 1

How to check if the command user has a specific role in discord?

So I'm making a discord bot but I wan't to make some of the commands only usable by a specific role Here is the code:

 @client.command()
async def mute(ctx,member : discord.Member):
 
  muted_role = ctx.guild.get_role(I don't know if i should share this role id so just imagine there is a role id here)

  await member.add_roles(muted_role)

  await ctx.send(member.mention + " has been muted")

Upvotes: 0

Views: 31

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15728

You can simply use the has_role decorator

@client.command()
@commands.has_role(198723981723) # Or the role name
async def mute(ctx, member: discord.Member):

Reference:

Upvotes: 2

Related Questions