#How to detect this?

1 messages · Page 1 of 1 (latest)

dire yacht
#

I want to handle this error

but I don't know how to handle it (cause i don't know the actual name of this error)
it's saying that the bot does not has enough permission to kick/ban a member that has higher role than them

#

How to detect this?

stable tartan
#

you can do it for every command or a global check

#
@commandname.error
async def commandname_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
.
.
.

this would be a basic one

dire yacht
stable tartan
#

with on_command_error it would check it global

dire yacht
#

ok

#

(mods don't archive this post please)

fierce mountain
#

If you use slash commands it should be on_application_command_error

dire yacht
fair crane
dire yacht
#

...

#

need help

#

Application Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

fair crane
#

Nope sorry

dire yacht
fair crane
#

I can’t help

dire yacht
#

i've tried many ways but still cant solve the problem

brittle sluice
#

Ignoring the error?

dire yacht
#

no

#
Application Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
brittle sluice
#

You cant

brittle sluice
worldly crown
dire yacht
worldly crown
#

well then

#

(hang on a sec)

#
if isinstance(error,commands.MissingRole):
  # put in what you want it to say
dire yacht
#

not MissingRole

#

it is forbidden

worldly crown
#

what does your command do?

#

maybe we can break down exactly what the perms it's missing

#

(also a tip)

before the if statements

do

async ...
  print(error)
  
  if isinstance....
#

maybe you can get the error that way

dire yacht
worldly crown
dire yacht
#

yes

dire yacht
# worldly crown did you try this? Also can you please send the code for the command
   @commands.slash_command(name="kick", description="Kicks a member from the server")
    @commands.has_permissions(moderate_members=True)
    async def kick(self, ctx, member: Option(discord.Member, required=True), reason: Option(str) = None):
        if reason == None:
            reason = "No reason provided"
        if member in ctx.guild.members:
            await ctx.guild.kick(member)
            await ctx.respond(f'User {member.mention} has been kicked for {reason} by {ctx.author.mention}')
        elif member.guild_permissions.moderate_members:
            await ctx.respond("You can't do this, this person is a moderator!")
            return
        elif ctx.author == member:
            await ctx.respond("You can't kick yourself, leave this server instead 😆")
            return
        elif member not in ctx.guild.members:
            await ctx.respond("You can't kick a user that is not in this server!")
            return
        else:
            pass

    @kick.error
    async def timeouterror(self, ctx, error):
        if isinstance(error, MissingPermissions):
            await ctx.respond(
                "You can't do this! You need to have moderate members permissions!"
            )
        elif isinstance(error, discord.Forbidden):
            await ctx.respond("The bot don't have permission to do this!\n You may need to check bot's permissions and place the bot's role on the top of the roles!")
        else:
            result = handle_error(error)
            await ctx.respond(f"{result[0]}", embeds=result[1])
worldly crown
#

uhhh is it timeouterror?

#

i thought it was um

#
async def on_application_command_error(ctx,error):
dire yacht
#

no

dire yacht
worldly crown
#

it might work?

dire yacht
#

...

dire yacht
nova cypress
nova cypress
#

sometimes, you may get the error type as discord.ApplicationCommandInvokeError

#

In these instances, the error has the attribute error.original which is the true error

dire yacht
#

error.original = 403 Forbidden (error code: 50013): Missing Permissions

teal rover
#

Then that means it’s missing permissions

dire yacht
#

the bot is missing permission

dire yacht
#

...