OpenClaw Discord Bot 配置完整指南

OpenClaw Discord Bot 配置完整指南

概述

本文档记录了 OpenClaw 与 Discord 集成的完整配置流程。配置成功将 main agent 绑定到 Discord,实现了多通道(Telegram + Discord)的统一 AI 助手体验。

配置时间线

  • 开始时间: 2026-03-06 08:06 UTC
  • 完成时间: 2026-03-06 11:13 UTC
  • 总耗时: 约3小时

前置条件

1. Discord 准备工作

  1. 创建 Discord 应用:

    • 访问 Discord Developer Portal
    • 点击 “New Application”,命名为 “OpenClaw”
    • 在左侧菜单选择 “Bot”,创建 bot
  2. 配置 Bot 权限:

    • 开启 Privileged Gateway Intents:
      • ✅ Message Content Intent (必需)
      • ✅ Server Members Intent (推荐)
    • 复制 Bot Token
  3. 获取 IDs:

    • 在 Discord 中开启 Developer Mode
    • 右键服务器图标 → “Copy Server ID”
    • 右键用户头像 → “Copy User ID”
  4. 邀请 Bot 到服务器:

    • 在 OAuth2 → URL Generator 生成邀请链接
    • 权限: bot, applications.commands
    • Bot 权限: View Channels, Send Messages, Read Message History, Embed Links, Attach Files

2. OpenClaw 环境

  • OpenClaw 2026.3.1+ 版本
  • Discord plugin 已启用
  • 至少一个 agent 已配置

配置步骤

步骤 1: 添加 Discord Channel

1
2
# 添加 Discord channel,使用 default 账户
openclaw channels add --channel discord --token "YOUR_BOT_TOKEN" --account default

步骤 2: 绑定 Agent 到 Discord

1
2
# 绑定 main agent 到 Discord
openclaw agents bind --agent main --bind Discord:default

步骤 3: 配置服务器白名单

编辑 ~/.openclaw/openclaw.json,在 channels.discord 部分添加 guilds 配置:

1
2
3
4
5
6
7
8
9
10
11
12
"discord": {
"enabled": true,
"token": "YOUR_BOT_TOKEN",
"groupPolicy": "allowlist",
"streaming": "off",
"guilds": {
"YOUR_SERVER_ID": {
"requireMention": false,
"users": ["YOUR_USER_ID"]
}
}
}

步骤 4: 配对流程

  1. 触发配对:

    • 在 Discord 中私信 bot
    • bot 会回复配对码
  2. 批准配对:

    1
    openclaw pairing approve discord PAIRING_CODE

步骤 5: 验证配置

1
2
3
4
5
6
7
8
# 检查通道状态
openclaw channels status --probe

# 检查 agent 绑定
openclaw agents list --bindings

# 检查配对状态
openclaw pairing list discord

故障排除

常见问题

  1. Bot 不响应消息

    • 检查 groupPolicy 配置
    • 验证 guilds 中的 Server ID 是否正确
  2. 配对失败

    • 检查 Bot Token 是否正确
    • 查看网关日志: openclaw logs --follow
  3. 权限问题

    • 确保 bot 在服务器中有适当权限
    • 检查 Privileged Intents 配置

诊断命令

1
2
3
4
5
# 详细状态检查
openclaw doctor

# 查看网关日志
openclaw logs --follow

与 Telegram 配置的差异

特性 Telegram Discord
账户创建 --account 参数必需 同左
配对机制 配对码批准 同左
服务器配置 groupAllowFrom guilds 对象
权限控制 allowFrom 列表 users 列表

高级配置

多 Discord Bots 配置

1
2
3
4
5
# 创建第二个 Discord account
openclaw channels add --channel discord --token "TOKEN_2" --account assistant

# 绑定另一个 agent
openclaw agents bind --agent searcher --bind Discord:assistant

流式响应配置

1
2
3
4
5
6
7
8
"discord": {
"streaming": "partial",
"draftChunk": {
"minChars": 200,
"maxChars": 800,
"breakPreference": "paragraph"
}
}

相关资源

  1. 官方文档: https://docs.openclaw.ai/channels/discord
  2. Discord Developer Portal: https://discord.com/developers
  3. OpenClaw CLI 参考: openclaw help channels

配置状态: ✅ 生产就绪
维护要求: 🔧 低(稳定配置)