This is my kick command which i have used in my bot
note: u need to write this thing before writting the command below ==> from discord.ext.commands import has_permissions, CheckFailure, BadArgument
@bot.command(pass_context=True, name="kick")
@has_permissions(kick_members=True)
async def kick(ctx, *, target: Member):
if target.server_permissions.administrator:
await bot.say("Target is an admin")
else:
try:
await bot.kick(target)
await bot.say("Kicked")
except Exception:
await bot.say("Something went wrong")
@kick.error
async def kick_error(error, ctx):
if isinstance(error, CheckFailure):
await bot.send_message(ctx.message.channel, "You do not have permissions")
elif isinstance(error, BadArgument):
await bot.send_message(ctx.message.channel, "Could not identify target")
else:
raise error
So now the command @bot.command(pass_context=True)
@has_permissions(kick_members=True) ==> It checks if
the user using that command has that permission or not. The rest of it is Self explanatory.
@kick.error parts checks the error on that kick command. Note: If in the first part u right async def kick_command in
@kick.error u must right @kick_command.error.
Also note:
in your bot command u have written @client=command.Bot(command_prefix='YOUR_PREFIX')
in the @bot.command()
u just have to change @bot to the thing u have written in that @client:
for ex. If u have wrriten @mybot.command_Bot(command_prefix='YOUR_PREFIX')
u have to change @bot to @mybot.command(). If u have any questions feel free to ask