Reputation:
I have a few roles in my discord like "Owner","Member" and "Jail". I want the bot to only be accessible by the "Owner" role and want the command to be something like this: .jail @user. Then the bot should take away the "Member" role and give them the "Jail" Role.
Discord Server latest update enter image description here
Upvotes: 0
Views: 2040
Reputation: 309
For making commands only accessible by a specific role do something like this:
@bot.command()
@commands.has_role("Name")
async def example(ctx):
await ctx.send("This was an example for R.Peter!")
And for adding / taking away roles do something like this:
@bot.command()
async def jail(ctx, member:discord.Member)
jailrole=get(guild.roles, name="Jail")
await member.add_roles(jailrole)
Taking away a role is the same except await member.add_roles(jailrole)
becomes
await member.remove_roles(jailrole)
Hopefully this answers your question!
Sources:
@commands.has_role("Name")
discord.py Docs
await member.add_roles(jailrole)
discord.py Docs
await member.remove_roles
discord.py Docs
Upvotes: 2