roles.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Chiaki-Nanami 作者: Ikusaba-san 项目源码 文件源码
def role_error(self, ctx, error):
        if not isinstance(error, commands.CommandInvokeError):
            return

        verb = ctx.command.callback.__name__.partition('_')[0]
        role = ctx.kwargs['name'] if verb == 'create' else ctx.kwargs['role']

        print(type(error.original))
        if isinstance(error.original, discord.Forbidden):
            if not ctx.guild.me.permissions_in(ctx.channel).manage_roles:
                await ctx.send('{ctx.author.mention}, I need the Manage roles permission pls...')

            # We can't modify an add, remove, or delete an integration role, obviously.
            elif getattr(role, 'managed', False):       # ->createrole uses a string for the role.
                await ctx.send(f"{role} is an intergration role, I can't do anything with that!")

            # Assume the role was too high otherwise.
            else:
                await ctx.send('The role was higher than my highest role. '
                               'Check the hierachy please! \U0001f605')

        elif isinstance(error.original, discord.HTTPException):      # Something strange happened.
            # will probably refactor this out into another function later.
            if verb.endswith('e'):
                verb = verb[:-1]

            message = (f'{verb.title()}ing {role} failed for some reason... '
                        'Send this error to the dev if you can:\n'
                       f'{type(error).__name__}: {error}')

            await ctx.send(message)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号