mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 01:40:15 +08:00
Hello Plugin
这是给 AstrBot SDK 插件作者准备的最小示例。
目录结构
hello_plugin/
├── plugin.yaml
├── requirements.txt
├── main.py
└── tests
└── test_plugin.py
能学到什么
- 如何定义一个
Star插件 - 如何注册命令 handler
- 如何使用
MessageEvent.reply() - 如何从
Context里读取当前插件元数据 - 如何用
MockContext/MockMessageEvent写插件测试
运行
在仓库根目录执行:
astrbot-sdk validate --plugin-dir examples/hello_plugin
astrbot-sdk dev --local --plugin-dir examples/hello_plugin --event-text hello
astrbot-sdk dev --local --watch --plugin-dir examples/hello_plugin --event-text hello
测试
python -m pytest examples/hello_plugin/tests/test_plugin.py -v
代码说明
hello: 最小命令,收到hello时回复Hello, World!about: 读取ctx.metadata.get_current_plugin(),演示 capability 客户端的基础用法