maintenance.py 文件源码

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

项目:endrebot0 作者: endreman0 项目源码 文件源码
def reload(ctx, *modules):
    for mod in modules:
        if mod == 'config':
            with open('config.json', encoding='utf-8') as f:
                ctx.bot.config = json.load(f)
        else:
            module_name = 'endrebot0.commands.{}'.format(mod)
            module = sys.modules.get(module_name)
            if module is not None:
                if hasattr(module, 'listeners'):
                    del module.listeners
                if hasattr(module, 'commands'):
                    del module.commands
            importlib.reload(module)
            ctx.bot.add_module(module)
            if hasattr(module, 'listeners'):
                for listener in module.listeners.get('on_ready', ()):
                    await listener(ctx.bot)
    return 'Reloaded %d module(s)' % len(modules)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号