discord py if statements permission 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)