繁体   English   中英

discord.py 中的 on_command_error 问题

[英]Problem with on_command_error in discord.py

您好,我想这样做,因此当您执行命令时,它会发送“看起来您缺少某些权限 - {此处的权限}”但它不起作用。 这是我的代码:

@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)}`')

这是一个很好的方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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