跳到主要内容OpenClaw 开源 AI 智能体部署指南:Discord 与微信接入配置 | 极客日志JavaScriptNode.jsWeChatAI
OpenClaw 开源 AI 智能体部署指南:Discord 与微信接入配置
综述由AI生成OpenClaw 开源 AI 智能体的多渠道接入配置指南。内容涵盖 Discord、微信(个人与企业)、Telegram、飞书、钉钉及 Slack 等平台的接入步骤与配置方法。重点讲解了 Wechaty 个人微信桥接方案的代码实现、企业微信回调配置以及 Docker 部署流程。此外,文章还提供了多模型配置、权限管理、安全实践、故障排查及实战案例(如代码审查、监控告警),帮助用户快速搭建稳定的 AI 自动化系统。
城市逃兵32 浏览 OpenClaw Discord 和微信接入配置指南
本文详细介绍如何配置 OpenClaw 的 Discord 和微信接入,包括企业微信和个人微信两种方案。
一、Discord 接入配置
1.1 为什么选择 Discord?
Discord 优势对比表:
| 特性 | Discord | Telegram | WhatsApp | 微信 |
|---|
| 国内可用性 | ✅ 可用 | ⚠️ 需换区 | ✅ 可用 | ✅ 可用 |
| 费用 | 🆓 免费 | 🆓 免费 | 💰 收费 | 🆓 免费 |
| Bot 创建难度 | ⭐ 简单 | ⭐⭐ 中等 | ⭐⭐⭐ 复杂 | ⭐⭐⭐⭐ 复杂 |
| 功能完整度 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ |
| 推荐度 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐ |
1.2 创建 Discord Bot
步骤 1:访问开发者门户
https:
步骤 2:创建应用
登录 Discord,点击 New Application,输入 Bot 名称,点击 Create。
步骤 3:创建 Bot
| 步骤 | 操作 | 说明 |
|---|
| 1 | 点击左侧 Bot | 进入 Bot 配置页面 |
| 2 | 点击 Add Bot | 创建 Bot |
| 3 | 点击 Reset Token | 生成新 Token |
| 4 | 复制 Token | ⚠️ 保存好,只显示一次 |
步骤 4:配置 Bot 权限
✅ Send Messages
✅ Read Message History
✅ Use Slash Commands
✅ Embed Links
✅ Attach Files
步骤 5:生成邀请链接
https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=2147483648&scope=bot
替换 YOUR_CLIENT_ID 为应用页面的 Application ID。
1.3 邀请 Bot 到服务器
打开邀请链接,请求授权,选择服务器,点击授权添加 Bot。
1.4 在 OpenClaw 中配置
openclaw onboard
? Select messaging platform: Discord
? Enter Discord Bot Token: MTIzNDU2Nzg5MDEyMzQ1Njc4OTAuGh_xyz.abcdefghijklmnopqrstuvwxyz1234567890
✅ Discord integration configured successfully!
1.5 启动并测试
openclaw gateway start
openclaw gateway --bind loopback --port 18789 --verbose
🦞 OpenClaw 2026.3.2 — Gateway started
Listening on http://127.0.0.1:18789
Discord Bot connected: YourBotName#1234
二、微信接入配置
2.1 微信接入方案对比
| 方案 | 类型 | 难度 | 费用 | 推荐度 | 说明 |
|---|
| 个人微信(Wechaty) | 非官方 | ⭐⭐⭐ | 🆓 免费 | ⭐⭐⭐⭐ | 适合个人使用 |
| 企业微信 | 官方 | ⭐⭐⭐⭐ | 🆓 免费 | ⭐⭐⭐⭐⭐ | 适合企业 |
| 微信公众号 | 官方 | ⭐⭐⭐⭐ | 🆓 免费 | ⭐⭐⭐ | 适合服务号 |
| 微信小程序 | 官方 | ⭐⭐⭐⭐⭐ | 🆓 免费 | ⭐⭐ | 开发复杂 |
2.2 方案一:个人微信(Wechaty)
2.2.1 什么是 Wechaty?
Wechaty 是一个开源的微信个人号接口,可以让你的个人微信号变成 Bot。
2.2.2 安装 Wechaty
mkdir -p ~/.openclaw/wechaty
cd ~/.openclaw/wechaty
npm init -y
npm install wechaty
node bot.js
完整 bot.js 代码
将以下内容保存为 ~/.openclaw/wechaty/bot.js。
const { WechatyBuilder } = require('wechaty')
const OPENCLAW_URL = process.env.OPENCLAW_URL || 'http://127.0.0.1:18789'
const BOT_NAME = process.env.BOT_NAME || 'openclaw-bot'
const OPENCLAW_API = `${OPENCLAW_URL.replace(/\/$/, '')}/api/message`
const bot = WechatyBuilder.build({ name: BOT_NAME })
bot.on('scan', (qrcode, status) => {
const url = `https://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`
console.log(`[扫码] 状态:${status}`)
console.log(`[扫码] 请用微信扫描:${url}`)
})
bot.on('login', (user) => {
console.log(`[登录] ✅ ${user.name()} 已登录`)
})
bot.on('logout', (user) => {
console.log(`[登出] ${user.name()} 已退出`)
})
bot.on('message', async (message) => {
if (message.self()) return
const text = message.text()?.trim()
if (!text) return
const talker = message.talker()
const room = message.room()
const from = room ? `群[${room.topic()}]@${talker.name()}` : talker.name()
console.log(`[消息] ${from}: ${text}`)
try {
const response = await fetch(OPENCLAW_API, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
platform: 'wechat',
message: text,
userId: talker.id,
userName: talker.name(),
roomId: room?.id,
roomTopic: room?.topic(),
}),
})
if (!response.ok) {
throw new Error(`OpenClaw 返回 ${response.status}: ${response.statusText}`)
}
const result = await response.json()
const reply = result?.reply ?? result?.content ?? result?.text
if (reply) {
await message.say(String(reply))
} else {
await message.say('(OpenClaw 未返回有效回复)')
}
} catch (error) {
console.error('[错误] 转发/回复失败:', error.message)
await message.say(`收到:${text}\n(OpenClaw 未连接,请检查服务是否启动)`)
}
})
bot.on('error', (error) => {
console.error('[Bot 错误]', error)
})
console.log('🤖 Wechaty Bot 启动中...')
bot.start().then(() => console.log('✅ Bot 已就绪,等待扫码登录')).catch((err) => {
console.error('❌ 启动失败:', err)
process.exit(1)
})
| 配置项 | 说明 | 默认值 |
|---|
OPENCLAW_URL | OpenClaw Gateway 地址 | http://127.0.0.1:18789 |
BOT_NAME | Bot 名称(日志用) | openclaw-bot |
OPENCLAW_API | 消息转发 API 路径 | {OPENCLAW_URL}/api/message |
| 问题 | 原因 | 解决方案 |
|---|
Wechaty is not a constructor | Wechaty v1.x 已改为 Builder 模式 | 使用 const { WechatyBuilder } = require('wechaty') |
PuppetWechat is not a constructor | 不要用 wechaty-puppet-wechat | 只装 npm install wechaty,不指定 puppet |
| 频繁掉线 | 免费协议限制 | 考虑企业微信方案或付费 puppet |
2.2.4 配置 OpenClaw
在 OpenClaw 配置文件 ~/.openclaw/openclaw.json 中增加以下内容。
openclaw config set channels.wechat.enabled true
openclaw config set messaging.wechat.enabled true
openclaw config set messaging.wechat.endpoint "http://127.0.0.1:18789/api/message"
openclaw config set messaging.wechat.autoReply true
方式二:直接编辑配置文件
编辑 ~/.openclaw/openclaw.json,加入:
"channels": { "wechat": { "enabled": true } },
"messaging": { "wechat": { "enabled": true, "endpoint": "http://127.0.0.1:18789/api/message", "autoReply": true } }
2.3 方案二:企业微信(推荐)
2.3.1 为什么选择企业微信?
| 特性 | 个人微信(Wechaty) | 企业微信 |
|---|
| 官方支持 | ❌ 非官方 | ✅ 官方 |
| 稳定性 | ⭐⭐⭐ 可能被封 | ⭐⭐⭐⭐⭐ 稳定 |
| API 文档 | ⭐⭐⭐ 社区维护 | ⭐⭐⭐⭐⭐ 官方文档 |
2.3.2 注册企业微信
访问企业微信官网,注册企业,填写企业信息,管理员认证。
2.3.3 创建企业微信应用
2.3.4 获取企业信息
- CorpId(企业 ID)
- AgentId(应用 ID)
- Secret(应用密钥)
- Token & AESKey(用于验证签名)
2.3.5 配置 OpenClaw
npm install -g @openclaw/plugin-wework
openclaw config set wework.corpId "your_corp_id"
openclaw config set wework.agentId "your_agent_id"
openclaw config set wework.secret "your_secret"
openclaw config set wework.token "your_token"
openclaw config set wework.encodingAESKey "your_aes_key"
openclaw config set wework.callbackUrl "https://your-domain.com/wework/callback"
openclaw gateway start --enable-wework
2.3.6 配置回调服务器
server {
listen 80;
server_name your-domain.com;
location /wework/callback {
proxy_pass http://127.0.0.1:18789;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
npm install -g ngrok
ngrok http 18789
2.3.7 验证配置
openclaw gateway start --verbose
openclaw logs --tail 50
三、其他消息渠道配置
3.1 Telegram 配置
openclaw config set telegram.token "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
openclaw gateway start --enable-telegram
3.2 飞书配置
openclaw config set feishu.appId "cli_xxxxxxxx"
openclaw config set feishu.appSecret "xxxxxxxxxxxxxxxx"
openclaw config set feishu.verificationToken "xxxxxxxx"
openclaw config set feishu.encryptKey "xxxxxxxx"
openclaw gateway start --enable-feishu
3.3 钉钉配置
openclaw config set dingtalk.webhook "https://oapi.dingtalk.com/robot/send?access_token=xxxxx"
openclaw config set dingtalk.secret "SECxxxxxxxxxx"
openclaw gateway start --enable-dingtalk
3.4 Slack 配置
openclaw config set slack.token "xoxb-xxxxxxxxxxxxx"
openclaw config set slack.signingSecret "xxxxxxxxxxxxxxxx"
openclaw gateway start --enable-slack
3.5 消息渠道全面对比表
| 渠道 | 国内可用 | 费用 | 配置难度 | 功能完整度 | 推荐度 |
|---|
| Discord | ✅ 可用 | 🆓 免费 | ⭐ 简单 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| 企业微信 | ✅ 可用 | 🆓 免费 | ⭐⭐⭐ 中等 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| 个人微信 | ✅ 可用 | 🆓 免费 | ⭐⭐⭐ 中等 | ⭐⭐⭐ | ⭐⭐⭐⭐ |
| 飞书 | ✅ 可用 | 🆓 免费 | ⭐⭐⭐ 中等 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| 钉钉 | ✅ 可用 | 🆓 免费 | ⭐⭐ 简单 | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
| Telegram | ⚠️ 需换区 | 🆓 免费 | ⭐⭐ 简单 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Slack | ✅ 可用 | 💰 部分收费 | ⭐⭐ 简单 | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
四、高级配置
4.1 多模型配置
openclaw config set ai.claude.apiKey "sk-ant-xxxxx"
openclaw config set ai.claude.model "claude-3-5-sonnet-20241022"
openclaw config set ai.openai.apiKey "sk-xxxxx"
openclaw config set ai.openai.model "gpt-4"
openclaw config set ai.qwen.apiKey "sk-xxxxx"
openclaw config set ai.qwen.model "qwen-max"
openclaw config set ai.default "claude"
4.2 自定义提示词(Prompt)
openclaw config edit prompts
4.3 权限管理
openclaw config set auth.admins "user_id_1,user_id_2"
openclaw config set auth.whitelist "user_id_3,user_id_4"
openclaw config set auth.enabled true
4.4 Docker 部署
FROM node:22-alpine
RUN npm install -g openclaw@latest
WORKDIR /app
COPY config.json /root/.openclaw/config.json
EXPOSE 18789
CMD ["openclaw", "gateway", "start", "--bind", "0.0.0.0", "--port", "18789"]
五、常见问题
5.1 安装问题
Error: OpenClaw requires Node.js >=22.0.0
nvm install 22
nvm use 22
node -v
5.2 配置问题
| 检查项 | 命令 | 预期结果 |
|---|
| Token 是否正确 | openclaw config get discord.token | 显示 Token |
| Bot 是否在线 | 查看 Discord 开发者门户 | 显示在线 |
| 权限是否足够 | 检查 Bot 权限 | 有发送消息权限 |
- 检查 Token 是否正确
- 检查 AESKey 是否正确
- 测试 URL 可访问性
- 检查防火墙端口
5.3 运行问题
openclaw gateway start --port 18790
lsof -ti:18789 | xargs kill -9
export NODE_OPTIONS="--max-old-space-size=4096"
openclaw gateway start
六、实战案例
6.1 自动化代码审查
openclaw config set prompts.codeReview "请审查以下代码,重点关注:1. 安全漏洞 2. 性能问题 3. 代码规范 4. 最佳实践"
6.2 企业微信日报提醒
const schedule = require('node-schedule');
const axios = require('axios');
schedule.scheduleJob('0 17 * * *', async () => {
const message = {
msgtype: 'text',
text: { content: '📝 提醒:请在下班前提交今日工作日报!' }
};
await axios.post('http://127.0.0.1:18789/api/wework/send', message);
});
6.3 多语言翻译助手
openclaw config set features.translation.enabled true
openclaw config set features.translation.languages "en,zh,ja,ko"
6.4 服务器监控告警
const os = require('os');
const axios = require('axios');
setInterval(async () => {
const cpuUsage = os.loadavg()[0] / os.cpus().length * 100;
const memUsage = (1 - os.freemem() / os.totalmem()) * 100;
if (cpuUsage > 80 || memUsage > 85) {
const alert = {
platform: 'discord',
message: `🚨 服务器告警!CPU 使用率:${cpuUsage.toFixed(2)}%`
};
await axios.post('http://127.0.0.1:18789/api/alert', alert);
}
}, 60000);
七、最佳实践
7.1 配置管理
NODE_ENV=production
OPENCLAW_PORT=18789
DISCORD_TOKEN=MTIzNDU2...
WEWORK_CORP_ID=wwxxxx
7.2 安全实践
- ✅ 启用 HTTPS
- ✅ 设置强密码认证
- ✅ 定期更换密钥
- ✅ 开启日志审计
7.3 备份恢复
BACKUP_DIR=~/.openclaw/backups
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
cp ~/.openclaw/config.json $BACKUP_DIR/config_$DATE.json
八、故障排查
8.1 诊断工具
openclaw health check
openclaw diagnose --verbose
openclaw test connection --platform discord
8.2 日志分析
openclaw logs --follow
openclaw logs --level error
8.3 常见错误码
| 错误码 | 说明 | 解决方案 |
|---|
| E001 | 配置文件错误 | 检查配置文件语法 |
| E002 | API Key 无效 | 重新获取 API Key |
| E003 | 网络连接失败 | 检查网络和防火墙 |
| E004 | 权限不足 | 检查权限配置 |
| E005 | 资源不足 | 增加资源或清理 |
总结
OpenClaw 支持多种消息渠道接入,包括 Discord、企业微信、个人微信等。部署时需注意 Node.js 版本(>=22),合理配置环境变量,并关注安全性与性能优化。通过灵活的高级配置,可实现代码审查、定时提醒、监控告警等多种自动化场景。
相关免费在线工具
- RSA密钥对生成器
生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online
- Mermaid 预览与可视化编辑
基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online
- 随机西班牙地址生成器
随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online
- Keycode 信息
查找任何按下的键的javascript键代码、代码、位置和修饰符。 在线工具,Keycode 信息在线工具,online
- Escape 与 Native 编解码
JavaScript 字符串转义/反转义;Java 风格 \uXXXX(Native2Ascii)编码与解码。 在线工具,Escape 与 Native 编解码在线工具,online
- JavaScript / HTML 格式化
使用 Prettier 在浏览器内格式化 JavaScript 或 HTML 片段。 在线工具,JavaScript / HTML 格式化在线工具,online