Discord 频道接入 OpenClaw 安装调试总结

2026年04月01日3 次阅读0 人喜欢
OpenClawDiscordBot代理Mihomo

Discord 频道接入 OpenClaw 安装调试总结

一、安装过程

1. 创建 Discord Bot

步骤:

  1. 访问 Discord Developer Portal: https://discord.com/developers/applications
  2. 创建新应用(如 "OpenClaw Bot")
  3. 添加 Bot 到应用
  4. 配置特权权限:
    • Message Content Intent(必需)
    • Server Members Intent(推荐)
  5. 获取 Bot Token
  6. 配置 OAuth2 URL Generator:
    • Scopes: bot + applications.commands
    • Permissions: 查看频道、发送消息、阅读消息历史、嵌入链接、附加文件
    • Integration Type: 服务器安装(Guild Install)

生成的授权 URL:

复制代码
https://discord.com/oauth2/authorize?client_id=<YOUR_CLIENT_ID>&permissions=2262240812596336&scope=bot%20applications.commands&integration_type=0

2. 添加 Bot 到服务器

  1. 浏览器打开授权 URL
  2. 选择目标服务器
  3. 点击授权
  4. 检查服务器成员列表,确认 Bot 已添加

3. 配置 OpenClaw

编辑配置文件: ~/.openclaw/openclaw.json

json 复制代码
{
  "plugins": {
    "allow": [
      "telegram",
      "weibo-openclaw-plugin",
      "feishu",
      "discord"
    ]
  },
  "channels": {
    "discord": {
      "enabled": true,
      "token": "<YOUR_BOT_TOKEN>",
      "groupPolicy": "allowlist",
      "guilds": {
        "<YOUR_SERVER_ID>": {
          "requireMention": false,
          "users": ["<YOUR_USER_ID>"]
        }
      },
      "streaming": "off",
      "proxy": "http://127.0.0.1:7890"
    }
  }
}

关键配置项:

  • token: Discord Bot Token(注意保密,不要泄露)
  • groupPolicy: allowlist(白名单模式)
  • guilds: 允许的服务器配置
  • proxy: HTTP 代理端口(用于 Discord Gateway 连接)

4. 重启 OpenClaw 网关

bash 复制代码
openclaw gateway restart

二、踩坑点总结

坑 1:插件未启用

问题: Discord 频道没启动,日志里完全没有 Discord 相关信息。

原因: plugins.allow 里没有 discord

解决:

json 复制代码
{
  "plugins": {
    "allow": [
      "telegram",
      "weibo-openclaw-plugin",
      "feishu",
      "discord"
    ]
  }
}

坑 2:代理配置错误(SOCKS5 不兼容 WebSocket)

问题:

复制代码
discord gateway error: Error: Proxy connection ended before receiving CONNECT response

原因: Discord Gateway 使用 WebSocket 连接,SOCKS5 代理不兼容 WebSocket 升级。

解决: 改用 HTTP 代理

json 复制代码
"discord": {
  "proxy": "http://127.0.0.1:7890"  // 而不是 socks5://127.0.0.1:7891
}

坑 3:应用程序命令部署失败

问题: Slash Command(/model)显示 "应用程序未响应"

原因: Discord 应用程序命令(applications.commands)部署失败,网络请求超时。

日志错误:

复制代码
discord startup [default] deploy-rest:put:error ... error=fetch failed

解决:

  1. 确保 Discord Bot 的 OAuth2 URL 包含 applications.commands scope
  2. 等待 Discord 同步命令(2-3 分钟)
  3. 检查网络连接(代理是否正常)

坑 4:TUN 模式配置问题

问题: 以为需要 TUN 模式才能让 Discord 走代理。

实际:

  • Mihomo 的手动代理模式已经可以代理 Discord 流量
  • 只要在 OpenClaw 配置里指定 proxy 即可
  • TUN 模式是全局代理,不是必需的

坑 5:配置热重载

问题: 修改配置后需要手动重启网关。

实际: OpenClaw 支持配置热重载(hot reload),修改 openclaw.json 后会自动重新加载频道。

日志证据:

复制代码
config hot reload applied (channels.discord.proxy)

坑 6:用户 ID 格式

问题: 配置里的 users 字段应该用 Discord 用户 ID,不是 Telegram 用户 ID。

检查方法:

  1. Discord 设置 → 高级 → 开启开发者模式
  2. 右键自己 → 复制用户 ID
  3. 对比配置里的 ID

三、验证步骤

1. 检查网关状态

bash 复制代码
openclaw gateway status

2. 检查 Discord 日志

bash 复制代码
tail -100 /tmp/openclaw/openclaw-2026-04-01.log | grep -i discord

成功标志:

复制代码
logged in to discord

3. 检查 Discord 服务器

  1. 服务器成员列表里能看到 Bot
  2. 输入 / 看命令列表
  3. 尝试 /model 命令

四、最终配置

OpenClaw 配置(成功状态)

json 复制代码
{
  "plugins": {
    "allow": [
      "telegram",
      "weibo-openclaw-plugin",
      "feishu",
      "discord"
    ]
  },
  "channels": {
    "discord": {
      "enabled": true,
      "token": "<YOUR_BOT_TOKEN>",
      "groupPolicy": "allowlist",
      "guilds": {
        "<YOUR_SERVER_ID>": {
          "requireMention": false,
          "users": ["<YOUR_USER_ID>"]
        }
      },
      "streaming": "off",
      "proxy": "http://127.0.0.1:7890"
    }
  }
}

注意: 配置中的 <YOUR_BOT_TOKEN><YOUR_SERVER_ID><YOUR_USER_ID> 需要替换为你自己的实际值。

Mihomo 配置要点

  • HTTP 代理端口:7890
  • SOCKS5 代理端口:7891
  • 手动代理模式(无需 TUN)
  • 确保 Discord 域名走代理规则

五、总结

成功关键点

  1. ✅ 启用 Discord 插件(plugins.allow 添加 discord
  2. ✅ 使用 HTTP 代理而非 SOCKS5(WebSocket 兼容性)
  3. ✅ OAuth2 URL 包含 applications.commands scope
  4. ✅ 配置热重载自动生效
  5. ✅ 确保网络代理正常工作

核心问题

  • WebSocket 代理兼容性:SOCKS5 不支持 WebSocket 升级,改用 HTTP 代理
  • 应用程序命令部署:需要 applications.commands scope 和稳定的网络连接
  • 配置热重载:OpenClaw 自动检测配置变化并重新加载-

建议

  1. 优先使用 HTTP 代理(端口 7890)
  2. 确保 Discord Bot 的 OAuth2 URL 包含 applications.commands
  3. 等待 Discord 同步命令(2-3 分钟)
  4. 检查日志确认连接状态
  5. 注意:Bot Token 等敏感信息务必保密,不要公开分享
加载评论中...