Skip to content Skip to sidebar Skip to footer

Discord.py: How Would You Restrict A Certain Command To A Role Or People With Specific Permissions?

Could someone show how you'd restrict, for example, the following command to lets say a role named 'Moderator' or only to people that have kick permissions? I don't quite understan

Solution 1:

To restrict commands to certain roles named "Moderator" or "Admin" use has_any_role

@client.command(pass_context=True)
@commands.has_any_role("Moderator", "Admin")
async def kick(ctx, member: discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.channel.send(f'{member.mention} has been kicked.')

To restrict commands to certain permissions of roles for example if a role has administrator you use has_permissions

@client.command(pass_context=True)@commands.has_permissions(administrator=True)asyncdefkick(ctx, member: discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.channel.send(f'{member.mention} has been kicked.')

Post a Comment for "Discord.py: How Would You Restrict A Certain Command To A Role Or People With Specific Permissions?"