📖 前言

OpenClaw 是一个强大的 AI Agent 框架,支持接入 QQ 频道、微信等多个平台。本文将详细介绍如何在 OpenClaw 中安装 QQ 频道机器人,并实现多机器人、多角色的配置方案。


🚀 一、QQ 频道机器人安装

打开qq开放平台,自动弹出OpenClaw 机器人,然后添加完后,会生成代码

#安装插件,只需要一次
openclaw plugins install @tencent-connect/openclaw-qqbot@latest
#添加机器人 不可以添加多个
openclaw channels add --channel qqbot --token "id:key"
#重启openclaw
openclaw gateway restart

1.4 验证安装

# 查看已安装的频道
openclaw channels list

# 查看网关状态
openclaw gateway status

🤖 二、多机器人配置

通过配置文件手动编辑

编辑 OpenClaw 配置文件(通常位于 ~/.openclaw/openclaw.json):

{
  "channels": {
    "qqbot": {
      "enabled": true,
      "allowFrom": ["*"],
      "accounts": {
        "coder": {
          "allowFrom": ["*"],
          "appId": "id1",
          "clientSecret": "你的第一个机器人密钥"
        },
        "supporter": {
          "allowFrom": ["*"],
          "appId": "id2",
          "clientSecret": "你的第二个机器人密钥"
        },
        "assistant": {
          "allowFrom": ["*"],
          "appId": "id3",
          "clientSecret": "你的第三个机器人密钥"
        }
      }
    }
  }
}

配置字段说明:

  • enabled:是否启用 QQ 频道
  • allowFrom:允许访问的来源,["*"] 表示允许所有人
  • accounts:机器人账号列表
    • coder:自定义账号 ID(用于绑定)
    • appId:QQ 开放平台的 AppID
    • clientSecret:QQ 开放平台的密钥

🎭 三、创建多角色 Agent

3.1 创建不同角色的 Agent

# 创建程序员 Agent
openclaw agents add code --workspace ~/.openclaw/workspace/code

# 创建技术支持 Agent
openclaw agents add support --workspace ~/.openclaw/workspace/support

# 创建客服 Agent
openclaw agents add service --workspace ~/.openclaw/workspace/service

# 创建视频剪辑 Agent
openclaw agents add video --workspace ~/.openclaw/workspace/video

3.2 删除不需要的 Agent

openclaw agents delete 代理id

🔗 四、绑定 Agent 到 QQ 机器人

4.1 基础绑定命令

# 语法
openclaw agents bind --agent <AgentID> --bind qqbot:<账号ID>

# 示例:将程序员 Agent 绑定到 coder 机器人
openclaw agents bind --agent code --bind qqbot:coder 

4.2 查看绑定状态

# 查看所有 Agent 及其绑定
openclaw agents list --bindings

# 查看特定 Agent 的绑定
openclaw agents get code

4.3 解除绑定

openclaw agents unbind --agent code --bind qqbot:coder

📝 五、完整配置示例

以下是一个完整的 openclaw.json 配置示例,包含多 Agent 和多机器人:

{
  "agents": {
    "list": [
      {
        "id": "code",
        "workspace": "~/.openclaw/workspace/code",
        "model": "deepseek/deepseek-chat"
      },
      {
        "id": "support",
        "workspace": "~/.openclaw/workspace/support",
        "model": "deepseek/deepseek-chat"
      },
      {
        "id": "video",
        "workspace": "~/.openclaw/workspace/video",
        "model": "deepseek/deepseek-chat"
      }
    ]
  },
  "channels": {
    "qqbot": {
      "enabled": true,
      "allowFrom": ["*"],
      "accounts": {
        "coder_bot": {
          "allowFrom": ["*"],
          "appId": "1903756128",
          "clientSecret": "Qmwsb8RhmgNr7B1d"
        },
        "support_bot": {
          "allowFrom": ["*"],
          "appId": "1903756129",
          "clientSecret": "你的第二个机器人密钥"
        },
        "video_bot": {
          "allowFrom": ["*"],
          "appId": "1903756130",
          "clientSecret": "你的第三个机器人密钥"
        }
      }
    }
  },
  "bindings": [
    {
      "agentId": "code",
      "match": {
        "channel": "qqbot",
        "accountId": "coder_bot"
      }
    },
    {
      "agentId": "support",
      "match": {
        "channel": "qqbot",
        "accountId": "support_bot"
      }
    },
    {
      "agentId": "video",
      "match": {
        "channel": "qqbot",
        "accountId": "video_bot"
      }
    }
  ]
}

🔧 六、常见问题与解决方案

6.1 API Key 配置问题

错误信息: 未找到提供程序"deepseek"的 API 密钥

解决方案:

# 配置 DeepSeek API Key
openclaw onboard --auth-choice deepseek-api-key
# 然后输入你的 API Key

6.2 配对认证问题

错误信息: pairing required

解决方案:

# 查看待批准的配对请求
openclaw devices list

# 批准配对
openclaw devices approve <请求ID>

# 重启网关
openclaw gateway restart

6.3 配置文件格式错误

问题: JSON 格式不正确,包含注释

解决方案:

  • OpenClaw 的标准 JSON 配置文件不支持注释
  • 如需添加说明,建议使用单独文档
  • 或使用支持注释的 JSONC 格式(如果 OpenClaw 支持)

6.4 机器人无响应

排查步骤:

# 1. 检查网关状态
openclaw gateway status

# 2. 查看实时日志
openclaw logs --follow

# 3. 运行诊断
openclaw doctor

# 4. 重启所有服务
openclaw gateway restart

📌 七、注意事项

  1. QQ 开放平台要求

    • 需要在 QQ 开放平台注册并创建机器人
    • 机器人需要完成实名认证
    • 注意配置 IP 白名单
  2. API 密钥安全

    • 不要将包含密钥的配置文件提交到公开仓库
    • 建议使用环境变量管理敏感信息
  3. 多机器人限制

    • 每个 QQ 号只能绑定一个机器人
    • 不同机器人需要使用不同的 QQ 号注册
  4. 性能考虑

    • 多个 Agent 会占用更多系统资源
    • 建议根据服务器配置合理规划 Agent 数量

🎯 八、快速部署脚本

为了方便部署,可以将以下命令保存为脚本:

#!/bin/bash

# 安装 QQ 插件
openclaw plugins install @tencent-connect/openclaw-qqbot@latest

# 添加机器人账号
openclaw channels add --channel qqbot --token "1903756128:Qmwsb8RhmgNr7B1d"

# 创建 Agent
openclaw agents add code --workspace ~/.openclaw/workspace/code
openclaw agents add support --workspace ~/.openclaw/workspace/support

# 绑定 Agent 到机器人
openclaw agents bind --agent code --bind qqbot:coder_bot
openclaw agents bind --agent support --bind qqbot:support_bot

# 配置 API Key
openclaw onboard --auth-choice deepseek-api-key

# 重启网关
openclaw gateway restart

echo "部署完成!"

📚 九、总结

通过以上配置,你可以实现:

  • ✅ 在 OpenClaw 中接入 QQ 频道机器人
  • ✅ 配置多个 QQ 机器人账号
  • ✅ 创建不同角色的 Agent
  • ✅ 将 Agent 绑定到不同的机器人
  • ✅ 实现多机器人、多角色的智能对话系统

这样,你可以在同一个 QQ 群中部署多个不同功能的 AI 助手,让它们各司其职,协同工作!


参考资源:


本文档基于 OpenClaw 最新版本编写,如有更新请参考官方文档。

Logo

小龙虾开发者社区是 CSDN 旗下专注 OpenClaw 生态的官方阵地,聚焦技能开发、插件实践与部署教程,为开发者提供可直接落地的方案、工具与交流平台,助力高效构建与落地 AI 应用

更多推荐