用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/publieople/hermes-config-kit --skill astrbot-plugin-dev命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | astrbot-plugin-dev |
| description | AstrBot 插件开发 — 骨架、装饰器、配置 schema、LLM 工具、注册/发布、热重载验证。Fork 优先于从零写,文档先于代码。 |
AstrBot 4.x 插件开发规范与踩坑。覆盖:写新插件 / Fork 改造现有插件 / 加 LLM 工具 / 调配置 schema / 验证加载。
https://docs.astrbot.app/dev/star/plugin-new.html 是入口。文档站部分链接 404,改路径试试(/dev/star/guides/...、/dev/star/llm-tool.html 实际路径可能不同)。不要凭印象猜 API——这次对话中我曾在没确认 @filter.llm_tool 是否存在时就敢写代码,被用户打断。web_search "astrbot 插件 <关键词>" 找现成的。已经有 90% 相似插件就别造轮子——Fork + 改 3 行,胜过从零写 200 行。astrbot_plugin_Pic 已经支持栗次元,Fork 改造就是正确路径,不是从零写 astrbot_plugin_alcy_pic。ls ~/astrbot/data/plugins/ 确认插件真的装了,不能凭 memory 说"X 插件已装"。astrbot_plugin_xxx/
├── main.py # 入口,@register 类 + 装饰器方法
├── metadata.yaml # 插件元数据
├── _conf_schema.json # 配置 schema(可空 {})
└── requirements.txt # 依赖(可空,但 aiohttp/httpx 建议列)
完整模板见 templates/helloworld/(可作为 scaffold 复制)。
name: astrbot_plugin_xxx # 必须 astrbot_plugin_ 前缀,全小写,无空格
display_name: 展示名(可中文) # WebUI 显示名
desc: 一句话描述
version: v1.0.0 # v 前缀必须
author: YourName # Fork 时标注 ImNotBird / YourName
repo: https://github.com/you/repo
# 可选:
# short_desc: 卡片短描述
# support_platforms: [aiocqhttp, telegram, ...] # ADAPTER_NAME_2_TYPE key
# astrbot_version: ">=4.16,<5" # PEP 440 格式
{} 即可,文件不能缺)可配置项类型:string | text | int | float | bool | object | list | dict | file | template_list。字段含义:
type(必填)、description、hint、default、options(下拉)、editor_mode(代码编辑器)_special: select_provider / select_persona / select_knowledgebase 等(v4.0+)详见 references/conf-schema.md。
import os
from typing import AsyncGenerator, Optional
from astrbot.api.star import Context, Star, register
from astrbot.api.event import AstrMessageEvent, MessageEventResult
from astrbot.api.event.filter import (
llm_tool, command, event_message_type, EventMessageType,
)
from astrbot.api import logger
@register("astrbot_plugin_xxx", "YourName", "描述", "v1.0.0",
"https://github.com/you/repo")
class XxxPlugin(Star):
def __init__(self, context: Context, config: Optional[dict] = None):
super().__init__(context)
self.config = config or {}
@command("hi")
async def cmd_hi(self, event: AstrMessageEvent):
"""hi - 打招呼命令"""
yield event.plain_result(f"hi {event.get_sender_name()}")
@llm_tool(name="send_x")
async def llm_send_x(self, event: AstrMessageEvent, param: = ):
event.plain_result()
():
| 装饰器 | 模块 | 作用 | 关键参数 |
|---|---|---|---|
@register(name, author, desc, version, repo) | astrbot.api.star | 类装饰器,声明插件 | 全部必填 |
@command("name") | astrbot.api.event.filter | 注册命令(/name) | 命令名 |
@llm_tool(name="...") | astrbot.api.event.filter | 注册 LLM 工具 | name(默认函数名) |
@event_message_type(EventMessageType.ALL) | 同上 | 监听所有消息 | 事件类型 |
@regex("pattern") | 同上 | 正则匹配 | 模式 |
@on_using_llm_tool | 同上 | 当 AI 调工具时 | 工具名 |
@on_llm_tool_respond | 同上 | 工具响应时 | 工具名 |
LLM 工具函数签名:docstring 必须写 Args:\n xxx(type): desc,AstrBot 自动解析为 JSON Schema。支持类型:string | number | object | array | boolean。
详见 references/decorators.md。
# 纯文本
yield event.plain_result("hello")
# 图片(URL 或本地路径)
yield event.image_result("https://...") # 或本地路径
# 链式组合(推荐异步生成器)
yield event.chain_result([Plain("hi"), Image.fromURL(url)])
# 文件图片(本地)
yield event.make_result().file_image("/path/to.png")
# 主动发(不等用户): await event.send(msg)
完整 message_components 列表(Plain/Image/Record/Video/At/Reply/Face/Node/Forward/Share/Music/Poke/...)在 astrbot.core.message.components。
# 1. GitHub 上 fork
gh repo fork <upstream> --clone=false
# 例如:gh repo fork ImNotBird/astrbot_plugin_Pic
# 2. 克隆到本地 AstrBot 插件目录
cd ~/astrbot/data/plugins
gh repo clone <your_user>/<repo>
# 3. 改 metadata.yaml 的 name/author/version(同目录同名)
# 4. 改 main.py(加新装饰器、新功能)
# 5. 提交推送
cd ~/astrbot/data/plugins/<repo>
git add -A
git -c user.email=you@x -c user.name=you commit -F /tmp/msg
git push origin main
gh fork 自动加 upstream remote → git fetch upstream && git merge upstream/main 同步上游。
commit message 文件避免中文多行被 shell 吃换行,写到 /tmp/msg 再 git commit -F。
python3 -c "import ast; ast.parse(open('main.py').read())"@command / @llm_tool / @register 存在且参数对。scripts/check_plugin.py 可直接用。python3 -c "import json; json.load(open('_conf_schema.json'))"python3 -c "import yaml; yaml.safe_load(open('metadata.yaml'))"sudo systemctl restart astrbot + sudo journalctl -u astrbot --since '1 min ago' | grep -iE 'plugin <name>|llm tool: <tool>'成功标志:
[Core] Loading plugin astrbot_plugin_xxx ...
[Core] Added llm tool: <tool_name>
[Core] Plugin astrbot_plugin_xxx (vX.Y.Z) by Author: <desc>
热重载陷阱:@filter.command generator 在 system reload 时可能不重新绑定 → 改代码后必须 sudo systemctl restart astrbot,不能只 WebUI 触发热重载。
日志位置:AstrBot 4.x 单一日志走 systemd journal,不是 ~/astrbot/logs/(目录可能空)。用 sudo journalctl -u astrbot。
astrbot_plugin_<name>(全小写、_ 分隔)metadata.yaml 字段齐全(name/display_name/desc/version/author/repo)AstrBotDevs/AstrBot_Plugins_Collection(或自建索引)provider_settings.default_personality 或 WebUI 侧边栏 → 人格。插件里的 personality 字段是叠加补充,不替代。_conf_schema.json 缺失 vs "{}" 行为不同。空 dict = 显式无配置;缺文件 = 用插件自带默认。没有它,_conf_schema.json 不会被读。aiohttp 或 httpx。data/ 下:插件自身的目录会被更新/重装覆盖。数据存 ~/astrbot/data/<plugin_name>/。httpx 用 follow_redirects=True 自动跟,aiohttp 用 allow_redirects=True。str 进 LLM prompt 让其总结;返回 None 不进 prompt。要"发出去 + 总结"两边都要:yield 消息 + return 字符串。name 跟上游同名,装到 AstrBot 时会跟上游版本冲突 → 改 name 加后缀。templates/helloworld/references/decorators.md_conf_schema.json 详细字段:references/conf-schema.mdreferences/llm-tool-schema.mdscripts/check_plugin.pyscripts/verify_plugin.py