main.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:brochat-bot 作者: nluedtke 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号