Skip to content
广告 · 本站推荐广告

Discord - 游戏社区平台接入 ​

Discord 是全球最大的游戏与社区平台之一。通过创建 Discord Bot(机器人),可以将 OpenClaw 接入 Discord Server(服务器),实现自动化交互。

前置要求 ​

  • 一个 Discord 账号及拥有管理员权限的 Server
  • OpenClaw Gateway(网关)已安装并运行

接入步骤 ​

第一步:创建 Bot 并开启 Intents ​

  1. 打开 Discord Developer Portal,点击 New Application
  2. 在左侧 Bot 页面点击 Add Bot,记录 Bot Token(机器人令牌)
  3. 开启 Privileged Gateway Intents 中的 Message Content Intent 和 Server Members Intent

必须开启

不开启 Message Content Intent(消息内容意图),Bot 将无法读取消息内容,完全无法工作。

第二步:生成邀请链接并邀请 Bot ​

  1. 在 OAuth2 > URL Generator 中勾选 Scopes:bot、applications.commands
  2. 勾选 Bot Permissions:Send Messages、Read Message History、Use Slash Commands
  3. 复制 URL 在浏览器中打开,选择目标 Server 完成邀请

第三步:记录必要 ID ​

  • Server ID(服务器ID):右键服务器图标 > Copy Server ID
  • User ID(用户ID):右键头像 > Copy User ID

开启开发者模式

前往 Settings > Advanced > Developer Mode 开启后才能复制 ID。

第四步:配置 OpenClaw ​

通过 CLI(命令行)配置:

bash
openclaw config set channels.discord.enabled true --json
openclaw config set channels.discord.token '"YOUR_BOT_TOKEN"' --json
openclaw config set channels.discord.dmPolicy '"pairing"' --json

或直接编辑配置文件:

json5
{
  channels: {
    discord: {
      enabled: true,
      token: "YOUR_BOT_TOKEN",
      dmPolicy: "pairing",
      allowGuilds: ["YOUR_SERVER_ID"],   // Guild(服务器)白名单
      allowFrom: ["YOUR_USER_ID"]        // 用户白名单
    }
  }
}

第五步:重启 Gateway 并配对 ​

bash
openclaw gateway restart

在 Discord 中向 Bot 发送私聊消息,获取 Pairing Code(配对码)后批准:

bash
openclaw pairing approve discord <pairing-code>

Guild(服务器)白名单 ​

json5
{
  channels: {
    discord: {
      allowGuilds: ["1234567890", "0987654321"]
    }
  }
}

留空或省略则允许所有已加入的 Server。

Slash Commands(斜杠命令) ​

OpenClaw 自动注册以下命令,可能需要最多 1 小时生效:

命令说明
/ask向 Bot 提问
/reset重置当前对话上下文
/help显示帮助信息
/status查看 Bot 运行状态

Thread(帖子)支持 ​

json5
{
  channels: {
    discord: {
      useThreads: true,
      threadAutoArchive: 60    // 自动归档时间(分钟)
    }
  }
}

常见问题 ​

Bot 在线但不回复消息 ​

  1. 确认 Message Content Intent 已开启
  2. 确认 Bot 在目标 Channel 有发送和读取消息的权限
  3. 运行 openclaw logs --channel discord 查看详细错误

Slash Commands 未显示 ​

确保邀请链接中包含 applications.commands Scope(权限范围),新命令注册后可能需等待最多 1 小时。

🇨🇳 中国用户须知

Discord 在中国大陆访问不稳定,部分网络可直接访问,部分需要代理。

服务器部署建议:部署在中国境内时,建议配置代理确保稳定连接:

json5
{
  channels: {
    discord: {
      proxy: "http://your-proxy:port"
    }
  }
}

使用场景:Discord 在国内游戏社区和海外留学生群体中有一定用户基础,适合游戏社区客服和海外社群运营。

注册提示:Discord 注册不需要手机号,使用邮箱即可。

基于MIT协议开源 | 内容翻译自 官方文档,同步更新