discord.py has permissions code example
Example 1: python discord bot command permissions
@commands.guild_only()
@commands.is_owner()
@commands.is_nsfw()
@commands.has_role("name")
@commands.bot_has_role(11132312313213)
@commands.has_any_role(["role1","foo",11132312313213])
@commands.bot_has_any_role(*roles)
@commands.has_permissions([ban_members=True, kick_members=True])
@commands.bot_has_permissions(**perms)
@commands.has_guild_permissions(**perms)
@commands.bot_has_guild_permissions(**perms)
@commands.check(myfunction)
@commands.check_any(*myfunctions)
from discord.ext.commands.cooldowns import BucketType
@commands.cooldown(rate,per,BucketType)
@commands.max_concurrency(number, per=BucketType.default, *, wait=False)
Example 2: discord.py how to use permissions
from discord import Member
from discord.ext.commands import has_permissions, MissingPermissions
@bot.command(name="kick", pass_context=True)
@has_permissions(manage_roles=True, ban_members=True)
async def _kick(ctx, member: Member):
await bot.kick(member)
@_kick.error
async def kick_error(error, ctx):
if isinstance(error, MissingPermissions):
text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author)
await bot.send_message(ctx.message.channel, text)
Example 3: discord py check if user has permission return message if not
@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!")
Example 4: check if user has permission discord py admin discord.py
await client.send_message(ctx.message.channel, msg)