discord py if is owner code example
Example 1: discord.py ban
@commands.command()
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, user: discord.Member, *, reason):
await ctx.guild.ban(user, reason=reason)
await user.send(f"You have been banned in {ctx.guild} for {reason}")
await ctx.send(f"{user} has been successfully banned.")
Example 2: discord py check if user is administrator
from discord.ext.commands import Bot, has_permissions, CheckFailure
client = Bot()
@client.command(pass_context=True)
@has_permissions(administrator=True)
async def whoami(ctx):
msg = "You're an admin {}".format(ctx.message.author.mention)
await client.send_message(ctx.message.channel, msg)
@whoami.error
async def whoami_error(error, ctx):
if isinstance(error, CheckFailure):
msg = "You're an average joe {}".format(ctx.message.author.mention)
await client.send_message(ctx.message.channel, msg)