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
评论列表
文章目录