简体   繁体   中英

Problem with on_command_error in discord.py

Hello I wanted to make it so when you do a command it sends "It looks like your missing some permissions - {the permission here}" but it doesn't work. Here's my code:

@client.event
async def on_command_error(ctx, error):
    if isinstance(error,commands.MissingPermissions):
            print(error.missing_perms)
            await ctx.send(f' It looks like your missing some permissions - `{" & ".join(error.missing_perms)}`')

Here's a good way to do it :

async def on_command_error(self, ctx, error):
    # get the original exception
    error = getattr(error, 'original', error)
    
    if isinstance(error, commands.MissingPermissions):
        missing = [perm.replace('_', ' ').replace('guild', 'server').title() for perm in error.missing_perms]
        if len(missing) > 2:
            fmt = '{}, and {}'.format("**, **".join(missing[:-1]), missing[-1])
        else:
            fmt = ' and '.join(missing)
        _message = 'You need the **{}** permission(s) to use this command.'.format(fmt)
        await ctx.send(_message)
        return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM