run.py 文件源码

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

项目:docflow 作者: strinking 项目源码 文件源码
def on_command_error(ctx, error):  # pylint: disable=arguments-differ
        """Handles all errors returned from Commands."""

        async def send_error(description):
            """A small helper function which sends an Embed with red colour."""

            await ctx.send(embed=discord.Embed(
                description=description,
                colour=discord.Colour.red()
            ))

        if isinstance(error, commands.MissingRequiredArgument):
            await send_error(
                f'You are missing the parameter {error.param} for the Command.'
            )
        elif isinstance(error, commands.NoPrivateMessage):
            await send_error(
                'This Command cannot be used in Private Messages.'
            )
        elif isinstance(error, commands.BadArgument):
            await send_error(
                'You invoked the Command with the wrong type of arguments. Use'
                '`.help <command>` to get information about its usage.'
            )
        elif isinstance(error, commands.CommandInvokeError):
            await ctx.send(embed=discord.Embed(
                title='Exception in command occurred, traceback printed.',
                colour=discord.Colour.red()
            ))
            print(
                'In {0.command.qualified_name}:'.format(ctx),
                file=sys.stderr
            )
            traceback.print_tb(error.original.__traceback__)
            print(
                '{0.__class__.__name__}: {0}'.format(error.original),
                file=sys.stderr
            )
        elif isinstance(error, commands.CommandOnCooldown):
            await ctx.send(embed=discord.Embed(
                title='This Command is currently on cooldown.',
                colour=discord.Colour.red()
            ))
        elif isinstance(error, commands.CommandNotFound):
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号