def _on_command_error(self, error, ctx: commands.Context):
"""Fires when a command error occurs."""
if not self.log_channels or not isinstance(error, commands.CommandInvokeError):
return
destinations = [c for c in self.bot.get_all_channels() if c.id in self.log_channels]
destinations += [c for c in self.bot.private_channels if c.id in self.log_channels]
error_title = "Exception in command `{}` ¯\_(?)_/¯".format(ctx.command.qualified_name)
log = "".join(traceback.format_exception(type(error), error,
error.__traceback__))
channel = ctx.message.channel
embed = discord.Embed(title=error_title, colour=discord.Colour.red(), timestamp=ctx.message.timestamp)
embed.add_field(name="Invoker", value="{}\n({})".format(ctx.message.author.mention, str(ctx.message.author)))
embed.add_field(name="Content", value=ctx.message.content)
_channel_disp = "Private channel" if channel.is_private else "{}\n({})".format(channel.mention, channel.name)
embed.add_field(name="Channel", value=_channel_disp)
if not channel.is_private:
embed.add_field(name="Server", value=ctx.message.server.name)
for channel in destinations:
try:
await self.bot.send_message(channel, embed=embed)
except discord.errors.Forbidden: # If bot can't embed
msg = ("Invoker: {}\n"
"Content: {}\n"
"Channel: {}".format(str(ctx.message.author), ctx.message.content, _channel_disp))
if not channel.is_private:
msg += "\nServer : {}".format(ctx.message.server.name)
await self.bot.send_message(channel, box(msg))
for page in pagify(log):
await self.bot.send_message(channel, box(page, lang="py"))
评论列表
文章目录