ThisIDeaL
ThisIDeaL

Reputation: 1

Trying to do an error message of missing required permission for discord bot on python

I am making an discord bot on python, and I don't wanna that regular users used the moderation commands. I know how to do a check for permissions, @commands.has_permissions(kick_members=True), but I don't know how to do an error message of missing required permissions. I tried that:

@kick.error
async def kick_error(self, ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send(':redTick: You don\'t have permission to kick members.')

I found that on Stack Overflow

But in the cmd it says that: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: kick_error() missing 1 required positional argument: 'error'

And if I swapped 'ctx' and 'error', like async def kick_error(self, error, ctx):, it says the same thing, only instead of missing 1 required positional argument: 'error' he wrote missing 1 required positional argument: 'ctx'

How can I fix it? And is there another way to do it?

Upvotes: 0

Views: 200

Answers (1)

Just for fun
Just for fun

Reputation: 4225

You need to check if the error is instance of commands.MissingRequiredArgument

Seeing the error I assume that you are not in a cog, so remove self

@kick.error
async def kick_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send(':redTick: You don\'t have permission to kick members.')
    elif isinstance(error, commands.MissingRequiredArgument):
        await ctx.send("Missing Argument")
    else: raise(error) # for other errors so they dont get suppressed

Upvotes: 1

Related Questions