OpenClaw 通过官方 Discord Bot API 接入,支持私信、服务器频道、论坛频道和交互组件。
快速接入(9步)
1. 创建 Discord 应用和 Bot
前往 Discord Developer Portal,点击 New Application,命名为 OpenClaw。点击侧边栏 Bot,设置 Bot 用户名。
2. 开启 Privileged Intents
在 Bot 页面开启:
- Message Content Intent(必须)
- Server Members Intent(角色路由必需)
3. 复制 Bot Token
点击 Reset Token(首次生成),保存好 Token。
4. 生成邀请链接
OAuth2 → URL Generator,勾选 bot + applications.commands,Bot Permissions 选 View Channels、Send Messages、Read Message History、Embed Links、Attach Files。
5. 开启开发者模式并复制 ID
设置 → 高级 → 开发者模式。右键服务器图标复制 Server ID,右键头像复制 User ID。
6. 允许 Bot 私信
右键服务器图标 → 隐私设置 → 开启直接消息。
7. 安全配置 Token
openclaw config set channels.discord.token "YOUR_BOT_TOKEN" --json
openclaw config set channels.discord.enabled true --json
openclaw gateway restart或配置文件:
{
"channels": {
"discord": {
"enabled": true,
"token": "YOUR_BOT_TOKEN"
}
}
}8. 完成配对
向 Bot 发 DM,Bot 回复配对码后:
openclaw pairing list discord
openclaw pairing approve discord <CODE>设置服务器工作区
每个频道独立 Session,把服务器变成 AI 工作台:
{
"channels": {
"discord": {
"groupPolicy": "allowlist",
"guilds": {
"YOUR_SERVER_ID": {
"requireMention": false,
"users": ["YOUR_USER_ID"]
}
}
}
}
}Session 隔离规则:
| 场景 | Session Key |
|---|---|
| DM | agent:main:main |
| 服务器频道 | agent:<id>:discord:channel:<channelId> |
| 斜杠命令 | agent:<id>:discord:slash:<userId> |
角色路由
根据用户 Discord 角色路由到不同 Agent:
{
"bindings": [
{
"agentId": "coding",
"match": { "channel": "discord", "guildId": "SERVER_ID", "roles": ["DEV_ROLE_ID"] }
},
{
"agentId": "support",
"match": { "channel": "discord", "guildId": "SERVER_ID", "roles": ["SUPPORT_ROLE_ID"] }
}
]
}论坛频道
# 发到论坛父频道(自动创建 Thread)
openclaw message send --channel discord --target channel:<forumId> --message "标题\n正文"
# 显式创建 Thread
openclaw message thread create --channel discord --target channel:<forumId> --thread-name "标题" --message "正文"交互组件(Components v2)
支持按钮、下拉菜单和 Modal 表单:
{
"channel": "discord",
"action": "send",
"to": "channel:123456789",
"message": "请选择",
"components": {
"reusable": true,
"text": "做出选择",
"blocks": [
{
"type": "actions",
"buttons": [
{ "label": "批准", "style": "success" },
{ "label": "拒绝", "style": "danger" }
]
}
]
}
}故障排查
- Bot 无响应:检查 Token;确认开启 Message Content Intent;
openclaw logs --follow - 服务器消息被忽略:检查
guilds配置和groupPolicy - 配对失败:配对码 1 小时有效;确认服务器隐私设置开启了直接消息
原文:Discord - OpenClaw | 来源:OpenClaw 官方文档