def on_command_error(self, ctx, ex):
if getattr(ex, 'should_suppress', False):
logger.debug('Suppressing exception: %s', ex)
return
see_help = await ctx._('err.see_help', prefix=ctx.prefix, cmd=ctx.command.qualified_name) if ctx.command else\
'See my help for more information.'
if isinstance(ex, commands.errors.BadArgument):
message = str(ex)
if not message.endswith('.'):
message = message + '.'
await ctx.send(await ctx._('err.bad_arg', msg=message, see_help=see_help))
elif isinstance(ex, commands.errors.MissingRequiredArgument):
await ctx.send(await ctx._('err.uh_oh', ex=ex, see_help=see_help))
elif isinstance(ex, commands.NoPrivateMessage):
await ctx.send(await ctx._('err.not_in_dm'))
elif isinstance(ex, errors.InsufficientPermissions):
await ctx.send(ex)
elif isinstance(ex, commands.errors.DisabledCommand):
await ctx.send(await ctx._('err.globally_disabled'))
elif isinstance(ex, asyncio.TimeoutError):
await ctx.send(await ctx._('err.timeout'))
elif isinstance(ex, commands.errors.CommandInvokeError):
if isinstance(ex.original, discord.Forbidden):
if ctx.command.name == 'help':
# can't dm that person :(
try:
await ctx.send(await ctx._('err.dms_disabled', mention=ctx.author.mention))
except discord.Forbidden:
pass
return
return await self.handle_forbidden(ctx)
# get the traceback
tb = ''.join(traceback.format_exception(type(ex.original), ex.original, ex.original.__traceback__))
# form a good human-readable message
header = f'Command error: {type(ex.original).__name__}: {ex.original}'
message = header + '\n' + str(tb)
self.dispatch('uncaught_command_invoke_error', ex.original, (message, tb, ctx))
logger.error(message)
评论列表
文章目录