#Unable to catch exception

1 messages · Page 1 of 1 (latest)

wheat moon
#

Code

'''Deletes Messages'''
@bot.slash_command(name="delete" , description="Purge Your Sins")
@commands.has_permissions(manage_messages=True)
async def delete(ctx, amount :int):
  embed=discord.Embed()
  try:
      embed.description=f'Deleted {amount} message(s)'
      await ctx.channel.purge(limit=amount)
      await ctx.respond(embed=embed)

  except discord.ext.commands.errors.MissingPermissions:
    embed.description= "Missing Permissions"
    await ctx.respond(embed=embed)    

Error

  File "d:\Coding Stuff\CataniBOT\venv\lib\site-packages\discord\ext\commands\core.py", line 2062, in predicate
    raise MissingPermissions(missing)
discord.ext.commands.errors.MissingPermissions: You are missing Manage Messages permission(s) to run this command.
indigo halo
#

give yourself manage_messages permission in discord

#

also you should handle these in on_application_command_error

wheat moon
indigo halo
#

the proper place to handle check errors is in on_application_command_error event

indigo halo
#

you will need to use isinstance to compare the error object provided to the event