Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

discord.py – How to make a response when a user doesn't have perms to ban a user

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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!")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading