第一个插件
1. 新建 index.js
js
module.exports = {
name: 'hello-plugin',
async onMessage(ctx) {
const text = String(ctx.content || '').trim();
if (text !== '你好') return false;
await ctx.reply(`你好,${ctx.userName || '群友'}!`);
return true;
},
};2. 新建 plugin.json
json
{
"slug": "hello-plugin",
"name": "你好插件",
"version": "1.0.0",
"category": "聊天互动",
"description": "发送「你好」自动回复",
"entry": "index.js",
"icon": "👋",
"commands": ["你好"],
"changelog": "首个版本"
}3. 打包
把 plugin.json 和 index.js 打成 zip,后缀改为 .wwp:
text
hello-plugin.wwp
├─ plugin.json
└─ index.js4. 上传
text
插件生态 → 开发者中心 → 上传插件上传后进入待审核。
5. 审核通过并安装
管理员通过后:
- 插件出现在商店
- 进入插件详情 → 安装
- 我的插件 → 启用
- 机器人收到「你好」时回复
6. 给插件加配置页(可选)
想让用户自己改文案、开关、密钥,而不是写死在代码里?在 plugin.json 加一段 settings_schema,平台会自动渲染出和「群管家」一样的配置面板:
json
{
"settings_schema": [
{ "key": "enabled", "label": "启用插件", "type": "switch", "default": true, "section": "基础设置" },
{ "key": "reply_text", "label": "回复文案", "type": "text", "default": "你好呀", "required": true, "section": "基础设置" }
]
}代码里直接读 ctx.settings.reply_text。注意必须打成 .wwp 包上传,单文件 .js 不会带上配置页。
完整字段说明、7 种控件、条件显示与排查表见自定义配置页面。
调试
服务端日志会打印:
text
[uplugin:hello-plugin] ...如果没反应:
- 检查插件是否启用
- 检查机器人是否收到消息
- 检查
ctx.content是否包含前缀(@机器人 已被去掉) - 检查是否返回了
true
