NekoBot 插件的最小可用模板,演示基础 API 用法。
nekobot_plugin_example/
├── main.py 插件主程序(@plugin + @event_handler + 命令处理)
├── metadata.yaml 插件元数据(名称、版本、作者、仓库)
├── requirements.txt 插件依赖(留空 = 仅用框架内置)
└── README.md 自述文件
cd /path/to/nekobot/data/plugins
git clone https://github.com/Ringaire/nekobot_plugin_template.git example_plugin| 命令 | 说明 |
|---|---|
/hello |
插件自我介绍 |
/echo <文本> |
复读 |
/config |
查看插件配置 |
在 NekoBot 的 data/config.json → plugin_configs 中添加:
"example_plugin": {
"greeting": "你好,世界"
}from packages.decorators import event_handler, plugin
from packages.plugins.base import BasePlugin
@plugin(name="my_plugin", version="1.0.0", description="我的插件")
class MyPlugin(BasePlugin):
@event_handler(event="message", description="处理消息")
async def on_message(self, payload: dict) -> None:
text = payload.get("plain_text", "")
await self.reply(f"收到: {text}")| 方法 | 说明 |
|---|---|
self.reply(text) |
回复消息 |
self.get_config(key, default) |
读取插件配置 |
self.request_provider(name, ...) |
调用 LLM |
self.check_permissions(*perms) |
检查权限 |
self.context.execution |
执行上下文(用户、平台、范围) |