Skip to content Skip to sidebar Skip to footer

Check If User Has Permission In Discord.py

I am making a kick command for my discord.py bot. Here is some code that the kick command might be: async kick_command(self, ctx, userName: discord.User): prefix_used = c

Solution 1:

Try this:

@bot.command()
@has_permissions(kick_members=True)  
async def kick(self, ctx, Member: discord.Member):
          await bot.kick(Member)

@kick.error
async def kick_error(error, ctx):
   if isinstance(error, MissingPermissions):
       await ctx.send("You don't have permission to do that!")

don't forget to import the has_permissions: from discord.ext.commands import has_permissions

Solution 2:

There is actually a better way of doing this without importing. I would recommend not importing and just doing this the way I am showing below because it will save you some time if you plan to import all of those.

This doesn't require importing anything for has_permissions.

@commands.has_permissions(kick_members=True)  asyncdefkick(self, ctx, Member: discord.Member):
    await bot.kick(Member)

Post a Comment for "Check If User Has Permission In Discord.py"