asmbot.py 文件源码

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

项目:Discord-ASM-Bot 作者: Emzi0767 项目源码 文件源码
def on_command_error(self, context, exception):
        extype = type(exception)
        value = exception
        tback = exception.__traceback__
        exinfo = (extype, value, tback)

        exfmts = [s.replace("\\n", "") for s in traceback.format_exception(*exinfo)]
        exfmt = [""]

        for exf in exfmts:
            ci = len(exfmt) - 1
            if len(exfmt[ci]) + len(exf) + 1 > 1024:
                exfmt.append(exf)
            else:
                exfmt[ci] = exfmt[ci] + "\n" + exf

        if context.command is None:
            return
        cmd = context.command.qualified_name

        iex = exception.original if isinstance(exception, commands.CommandInvokeError) else None
        if iex and isinstance(iex, asmbot.AssemblerException):
            embed = self._embed(context, "Error assembling code", "An error occured when assembling code", "error")
            embed.add_field(name="Details", value=f"```\n{iex.clang_data}\n```", inline=False)
        else:
            embed = self._embed(context, "Error executing command", "An error occured when executing command `{}`".format(cmd), "error")

        asmbot.log(*exfmts, tag="CMD ERR")
        await context.message.channel.send(embed=embed)

    # Bot preparation
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号