mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-02-08 20:06:31 +08:00
033c90dd74
Some checks failed
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.11) (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.12) (push) Failing after 6m59s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.10) (push) Failing after 7m7s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.10) (push) Failing after 5m14s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.9) (push) Failing after 5m42s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.11) (push) Failing after 4m51s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.12) (push) Failing after 7m12s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.9) (push) Failing after 6m33s
Pyright Lint / Pyright Lint (pydantic-v1) (push) Failing after 8m12s
Ruff Lint / Ruff Lint (push) Successful in 43s
Pyright Lint / Pyright Lint (pydantic-v2) (push) Failing after 6m56s
Site Deploy / publish (push) Failing after 7m21s
3.3 KiB
3.3 KiB
mdx | sidebar_position | description | ||
---|---|---|---|---|
|
1 | nonebot.plugin.load 模块 |
nonebot.plugin.load
本模块定义插件加载接口。
def load_plugin(module_path)
-
说明: 加载单个插件,可以是本地插件或是通过
pip
安装的插件。 -
参数
module_path
(str | Path): 插件名称path.to.your.plugin
或插件路径pathlib.Path(path/to/your/plugin)
-
返回
- Plugin | None
def load_plugins(*plugin_dir)
-
说明: 导入文件夹下多个插件,以
_
开头的插件不会被导入! -
参数
*plugin_dir
(str): 文件夹路径
-
返回
- set[Plugin]
def load_all_plugins(module_path, plugin_dir)
-
说明: 导入指定列表中的插件以及指定目录下多个插件,以
_
开头的插件不会被导入! -
参数
-
module_path
(Iterable[str]): 指定插件集合 -
plugin_dir
(Iterable[str]): 指定文件夹路径集合
-
-
返回
- set[Plugin]
def load_from_json(file_path, encoding="utf-8")
-
说明: 导入指定 json 文件中的
plugins
以及plugin_dirs
下多个插件。 以_
开头的插件不会被导入! -
参数
-
file_path
(str): 指定 json 文件路径 -
encoding
(str): 指定 json 文件编码
-
-
返回
- set[Plugin]
-
用法
{ "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 文件编码
-
-
返回
- set[Plugin]
-
用法
[tool.nonebot] plugins = ["some_plugin"] plugin_dirs = ["some_dir"]
nonebot.load_from_toml("pyproject.toml")
def load_builtin_plugin(name)
-
说明: 导入 NoneBot 内置插件。
-
参数
name
(str): 插件名称
-
返回
- Plugin | None
def load_builtin_plugins(*plugins)
-
说明: 导入多个 NoneBot 内置插件。
-
参数
*plugins
(str): 插件名称列表
-
返回
- set[Plugin]
def require(name)
-
说明: 声明依赖插件。
-
参数
name
(str): 插件模块名或插件标识符,仅在已声明插件的情况下可使用标识符。
-
返回
- ModuleType
-
异常
- RuntimeError: 插件无法加载
def inherit_supported_adapters(*names)
-
说明
获取已加载插件的适配器支持状态集合。
如果传入了多个插件名称,返回值会自动取交集。
-
参数
*names
(str): 插件名称列表。
-
返回
- set[str] | None
-
异常
-
RuntimeError: 插件未加载
-
ValueError: 插件缺少元数据
-