check if bot has permission discord.py code example
Example 1: 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 2: 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 3: check if user has manage messages discord.py
@client.event
async def on_message(message):
message.author.guild_permissions.manage_messages
Example 4: check if user has permission discord py admin discord.py
await client.send_message(ctx.message.channel, msg)