def on_command_error(error, ctx):
if isinstance(error, commands.errors.CommandNotFound):
pass # ...don't need to know if commands don't exist
if isinstance(error, commands.errors.CheckFailure):
await bot.send_message(ctx.message.channel, "{} You don't have permission to use this command.".format(ctx.message.author.mention))
elif isinstance(error, commands.errors.MissingRequiredArgument):
formatter = commands.formatter.HelpFormatter()
await bot.send_message(ctx.message.channel, "{} You are missing required arguments.\n{}".format(ctx.message.author.mention, formatter.format_help_for(ctx, ctx.command)[0]))
elif isinstance(error, commands.errors.CommandOnCooldown):
try:
await bot.delete_message(ctx.message)
except discord.errors.NotFound:
pass
message = await bot.send_message(ctx.message.channel, "{} This command was used {:.2f}s ago and is on cooldown. Try again in {:.2f}s.".format(ctx.message.author.mention, error.cooldown.per - error.retry_after, error.retry_after))
await asyncio.sleep(10)
await bot.delete_message(message)
else:
await bot.send_message(ctx.message.channel, "An error occured while processing the `{}` command.".format(ctx.command.name))
print('Ignoring exception in command {0.command} in {0.message.channel}'.format(ctx))
mods_msg = "Exception occured in `{0.command}` in {0.message.channel.mention}".format(ctx)
# traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
tb = traceback.format_exception(type(error), error, error.__traceback__)
print(''.join(tb))
await bot.send_message(bot.boterr_channel, mods_msg + '\n```' + ''.join(tb) + '\n```')
# mostly taken from https://github.com/Rapptz/discord.py/blob/async/discord/client.py
评论列表
文章目录