mirror of
				https://github.com/nonebot/nonebot2.git
				synced 2025-11-04 00:46:43 +00:00 
			
		
		
		
	📝 update loading-a-plugin docs
This commit is contained in:
		@@ -39,10 +39,11 @@ if __name__ == "__main__":
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
在 `bot.py` 文件中添加以下行:
 | 
					在 `bot.py` 文件中添加以下行:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```python{5}
 | 
					```python{6}
 | 
				
			||||||
import nonebot
 | 
					import nonebot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
nonebot.init()
 | 
					nonebot.init()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 加载插件目录,该目录下为各插件,以下划线开头的插件将不会被加载
 | 
					# 加载插件目录,该目录下为各插件,以下划线开头的插件将不会被加载
 | 
				
			||||||
nonebot.load_plugins("awesome_bot/plugins")
 | 
					nonebot.load_plugins("awesome_bot/plugins")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,10 +69,11 @@ if __name__ == "__main__":
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
在 `bot.py` 文件中添加以下行:
 | 
					在 `bot.py` 文件中添加以下行:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```python{5,7}
 | 
					```python{6,8}
 | 
				
			||||||
import nonebot
 | 
					import nonebot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
nonebot.init()
 | 
					nonebot.init()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 加载一个 pip 安装的插件
 | 
					# 加载一个 pip 安装的插件
 | 
				
			||||||
nonebot.load_plugin("nonebot_plugin_status")
 | 
					nonebot.load_plugin("nonebot_plugin_status")
 | 
				
			||||||
# 加载本地的单独插件
 | 
					# 加载本地的单独插件
 | 
				
			||||||
@@ -83,6 +85,61 @@ if __name__ == "__main__":
 | 
				
			|||||||
    nonebot.run()
 | 
					    nonebot.run()
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 从 json 文件中加载插件
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					在 `bot.py` 文件中添加以下行:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```python{6}
 | 
				
			||||||
 | 
					import nonebot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nonebot.init()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 从 plugin.json 加载插件
 | 
				
			||||||
 | 
					load_from_json("plugin.json")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = nonebot.get_asgi()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    nonebot.run()
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**json 文件示例**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```json
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    "plugins": ["nonebot_plugin_status", "awesome_bot.plugins.xxx"],
 | 
				
			||||||
 | 
					    "plugin_dirs": ["awesome_bot/plugins"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 从 toml 文件中加载插件
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					在 `bot.py` 文件中添加以下行:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```python{6}
 | 
				
			||||||
 | 
					import nonebot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nonebot.init()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 从 pyproject.toml 加载插件
 | 
				
			||||||
 | 
					load_from_toml("pyproject.toml")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app = nonebot.get_asgi()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    nonebot.run()
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					**toml 文件示例:**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```toml
 | 
				
			||||||
 | 
					[nonebot.plugins]
 | 
				
			||||||
 | 
					plugins = ["nonebot_plugin_status", "awesome_bot.plugins.xxx"]
 | 
				
			||||||
 | 
					plugin_dirs = ["awesome_bot/plugins"]
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nb-cli 默认使用 `pyproject.toml` 加载插件。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 子插件(嵌套插件)
 | 
					## 子插件(嵌套插件)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
在插件中同样可以加载子插件,例如如下插件目录结构:
 | 
					在插件中同样可以加载子插件,例如如下插件目录结构:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user