im trying to make it that when you try to ban a user, but you dont have perms, it sends a message instead of just an error. Anyone have a fix?
@bot.tree.command(name='ban', description='Ban a user. (w/ perms only)')
@commands.has_permissions(ban_members = True)
async def ban(ctx,member : discord.Member,* , reason: str):
"""Ban a user"""
await ctx.response.send_message(member.name + " has been from banned the server for "+reason)
await member.ban(reason=reason)
i tried except: and else: but it didnt really work. Im very new to python and im not sure how to do this.
Edit: Does anyone know how to make the bot send a message when it tries to ban a admin and improper perms for the bot? thanks.
>Solution :
You can add a simple if statement which checks if the user has the permission to ban members:
if not ctx.user.guild_permissions.ban_members:
return await ctx.response.send_message("You are not allowed to do this!")