I am currently making a discord.py bot, but whenever I try to make a command that you need the permission for, it doesn't work. For an example here is my ban command:
@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member:discord.User=None, reason=None):
if member == None or member == ctx.author:
await ctx.channel.send("You must specify a user, and one that isn't you.")
return
if reason == None:
reason = "*Reason is not specified.*"
message = (f"You have been banned from **{ctx.guild.name}** for {reason}!")
await member.send(message)
await ctx.guild.ban(member, reason=reason)
await ctx.channel.send(f"{member} was banned!")
I've made sure I am the bot have the required permissions yet I still get this error:
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
I've tried lots and still haven't been able to get this to work, and its not only for this ban command, a 'setnick' command also has the same error. Please help me figure out the problem, thanks!
CodePudding user response:
You should try this :
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not have the permissions required for this command.")
return
CodePudding user response:
I figured it out: It was because the bot role was lower than the Member role, therefore the bot cannot ban the member.