def on_command_error(exception, context):
if type(exception) == commands.CommandOnCooldown:
await bot.send_message(context.message.channel,
"!{} is on cooldown for {:0.2f} seconds.".format(
context.command, exception.retry_after))
elif type(exception) == commands.CommandNotFound:
cmd = context.message.content.split()[0][1:]
try:
closest = get_close_matches(cmd.lower(), list(bot.commands))[0]
except IndexError:
await bot.send_message(context.message.channel,
"!{} is not a known command."
.format(cmd))
else:
await bot.send_message(context.message.channel,
"!{} is not a command, did you mean !{}?"
.format(cmd, closest))
elif type(exception) == commands.CheckFailure:
await bot.send_message(context.message.channel,
"You failed to meet a requirement for that "
"command.")
elif type(exception) == commands.MissingRequiredArgument:
await bot.send_message(context.message.channel,
"You are missing a required argument for that "
"command.")
else:
await bot.send_message(context.message.channel,
"Unhandled command error ({})"
.format(exception))
print('Ignoring exception in command {}'.format(context.command),
file=sys.stderr)
traceback.print_exception(type(exception), exception,
exception.__traceback__, file=sys.stderr)
评论列表
文章目录