nonebot2/website/versioned_docs/version-2.0.0-beta.5/api/plugin/load.md
github-actions[bot] e5e69c2726 🔖 Release 2.0.0-beta.5
2022-08-04 06:27:40 +00:00

2.9 KiB

sidebar_position description
1 nonebot.plugin.load 模块

nonebot.plugin.load

本模块定义插件加载接口。

def load_plugin(module_path)

  • 说明

    加载单个插件,可以是本地插件或是通过 pip 安装的插件。

  • 参数

    • module_path (str): 插件名称 path.to.your.plugin
  • 返回

def load_plugins(*plugin_dir)

  • 说明

    导入文件夹下多个插件,以 _ 开头的插件不会被导入!

  • 参数

    • *plugin_dir (str): 文件夹路径
  • 返回

def load_all_plugins(module_path, plugin_dir)

  • 说明

    导入指定列表中的插件以及指定目录下多个插件,以 _ 开头的插件不会被导入!

  • 参数

    • module_path (Iterable[str]): 指定插件集合

    • plugin_dir (Iterable[str]): 指定文件夹路径集合

  • 返回

def load_from_json(file_path, encoding='utf-8')

  • 说明

    导入指定 json 文件中的 plugins 以及 plugin_dirs 下多个插件,以 _ 开头的插件不会被导入!

  • 参数

    • file_path (str): 指定 json 文件路径

    • encoding (str): 指定 json 文件编码

  • 返回

  • 用法

    {
      "plugins": ["some_plugin"],
      "plugin_dirs": ["some_dir"]
    }
    
    nonebot.load_from_json("plugins.json")
    

def load_from_toml(file_path, encoding='utf-8')

  • 说明

    导入指定 toml 文件 [tool.nonebot] 中的 plugins 以及 plugin_dirs 下多个插件,以 _ 开头的插件不会被导入!

  • 参数

    • file_path (str): 指定 toml 文件路径

    • encoding (str): 指定 toml 文件编码

  • 返回

  • 用法

    [tool.nonebot]
    plugins = ["some_plugin"]
    plugin_dirs = ["some_dir"]
    
    nonebot.load_from_toml("pyproject.toml")
    

def load_builtin_plugin(name)

  • 说明

    导入 NoneBot 内置插件。

  • 参数

    • name (str): 插件名称
  • 返回

def load_builtin_plugins(*plugins)

  • 说明

    导入多个 NoneBot 内置插件。

  • 参数

    • *plugins (str): 插件名称列表
  • 返回

def require(name)

  • 说明

    获取一个插件的导出内容。

    如果为 load_plugins 文件夹导入的插件,则为文件(夹)名。

  • 参数

  • 返回

  • 异常

    • RuntimeError: 插件无法加载