【Hermes Agent 从入门到精通】第 12 篇:Discord / Slack 机器人搭建

本系列定位:零基础入门,从安装配置到高级架构全覆盖。无论你是开发者、运维工程师、还是技术爱好者,本系列带你彻底掌握 Hermes Agent。


本篇你将学到

  • Discord Bot 创建与配置
  • Message Content Intent 的关键注意事项
  • Slack App 创建与事件订阅
  • 群组中 @ 提及触发 Agent
  • 平台功能对比

学完本篇,你将在团队协作平台(Discord / Slack)上拥有一个 AI Agent。


一、Discord Bot 搭建

1.1 创建 Discord Application

  1. 访问 Discord Developer Portal
  2. 点击 New Application → 输入名称(如 Hermes Agent
  3. 进入 Bot 页面 → 点击 Add Bot
  4. 复制 Bot Token

1.2 配置 Intents(关键)

在 Bot 页面的 Privileged Gateway Intents 部分:

✅ PRESENCE INTENT          (不需要)
✅ SERVER MEMBERS INTENT     (不需要)
✅ MESSAGE CONTENT INTENT    ← 必须开启!

Message Content Intent 必须开启——否则 Bot 收不到消息内容,对任何消息都「沉默」。这是最常见的 Discord Bot 问题。

1.3 邀请 Bot 到服务器

  1. 进入 OAuth2 → URL Generator
  2. 勾选 Scopes:bot
  3. 勾选 Bot Permissions:Send MessagesRead Message HistoryAttach Files
  4. 复制生成的 URL,在浏览器中打开
  5. 选择你的服务器 → 授权

1.4 配置 Hermes

hermes gateway setup

选择 Discord,输入 Token:

Enter Discord Bot Token: MTIzNDU2Nzg5...
✅ Discord configured!

或手动写入 .env

DISCORD_BOT_TOKEN=MTIzNDU2Nzg5...

1.5 启动并使用

hermes gateway restart

在 Discord 中:

# 私聊 Bot:直接发消息
你好,帮我看看今天的 Git 提交记录

# 在服务器频道中 @ Bot
@Hermes Agent 帮我分析一下这段代码的性能问题

在群组频道中,需要 @提及 Bot 才会触发响应。私聊中直接发消息即可。


下面是 Discord Bot 搭建的整体流程:

访问 Discord Developer Portal

创建 New Application

进入 Bot 页面 → Add Bot

复制 Bot Token

配置 Privileged Gateway Intents

MESSAGE CONTENT INTENT
是否开启?

❌ Bot 收不到消息内容

进入 OAuth2 → URL Generator

勾选 Scopes: bot
勾选 Permissions

复制 URL → 浏览器打开

选择服务器 → 授权

配置 Hermes
hermes gateway setup

输入 Bot Token

✅ Discord configured!

hermes gateway restart

🎉 Bot 上线运行

二、Slack Bot 搭建

2.1 创建 Slack App

  1. 访问 api.slack.com/apps
  2. 点击 Create New AppFrom scratch
  3. 输入 App 名称(如 Hermes Agent)→ 选择 Workspace

2.2 配置 OAuth & Permissions

进入 OAuth & Permissions 页面:

添加 Bot Token Scopes:

✅ chat:write          ← 发送消息
✅ app_mentions:read   ← 读取 @提及
✅ channels:history    ← 读取公共频道消息
✅ groups:history      ← 读取私有频道消息
✅ im:history          ← 读取 DM 消息
✅ files:read          ← 读取文件

channels:history 必须订阅——否则 Bot 只能在 DM 中工作,无法响应公共频道消息。

2.3 配置 Event Subscriptions

进入 Event Subscriptions 页面:

  1. 开启 Enable Events
  2. 订阅事件:
    • message.channels ← 公共频道消息
    • message.im ← 私聊消息
    • app_mention ← @提及事件

2.4 安装 App 获取 Token

点击 Install to Workspace → 获取两个 Token:

Bot User OAuth Token (xoxb-...)     ← Bot Token
Signing Secret (xxx...)             ← 签名密钥

2.5 配置 Hermes

# 写入 .env
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_SIGNING_SECRET=your-signing-secret
hermes gateway restart

2.6 使用

在 Slack 中:

# 私聊 Bot
@Hermes Agent 帮我总结一下今天的会议纪要

# 在频道中 @提及
@Hermes Agent 这个 PR 有什么问题?

下面是 Slack Bot 搭建的整体流程:

访问 api.slack.com/apps

Create New App
→ From scratch

输入 App 名称
选择 Workspace

配置 OAuth & Permissions

添加 Bot Token Scopes

chat:write
app_mentions:read
channels:history
groups:history
im:history
files:read

配置 Event Subscriptions

开启 Enable Events

订阅事件:
message.channels
message.im
app_mention

Install to Workspace

获取 Token:
Bot User OAuth Token
Signing Secret

写入 .env 配置

hermes gateway restart

🎉 Slack Bot 上线

三、平台功能对比

功能 Telegram Discord Slack
私聊
群组 ✅(需 @) ✅(需 @)
图片发送
语音消息 ✅(STT)
文件附件
Slash 命令
代码格式化 Markdown Markdown Markdown
Topic 会话 ✅(线程) ✅(线程)
文字上限 4096 字符 2000 字符 40000 字符
速率限制 宽松 宽松 较严

Telegram 文字上限:如果回复超过 4096 字符,Hermes 会自动分多条消息发送。


根据你的团队需求选择平台:

个人使用
快速原型

游戏社区
技术社群

企业团队
正式办公

选择平台

主要需求

Telegram

Discord

Slack

✅ 最灵活
语音消息支持
宽松速率限制

✅ 社区氛围好
线程支持
2000字符限制

✅ 企业级集成
40000字符上限
速率限制较严

推荐场景:
个人助手
快速实验

🎯 多平台同时运行
hermes gateway status

四、多平台同时运行

hermes gateway status
✅ Hermes Gateway is running (PID: 12345)

Platforms:
  Telegram:  @my_hermes_agent_bot    ✅ Connected
  Discord:   Hermes Agent#1234       ✅ Connected
  Slack:     @Hermes Agent           ✅ Connected

在 Telegram 问了一半,切到 Discord 继续——只要在同一 Profile 下,Session 可以跨平台恢复(通过 /resume)。


下面是 Hermes 多平台架构示意:

Hermes Core

Hermes Gateway

用户

消息

消息

消息

回复

回复

回复

回复

回复

回复

👤 Telegram 用户

👤 Discord 用户

👤 Slack 用户

Telegram Adapter

Discord Adapter

Slack Adapter

Session Manager
跨平台恢复

Agent Engine

Profile 管理

/resume 会话恢复

五、常见问题

Q1:Discord Bot 上线后完全不回复

检查 Message Content Intent 是否在 Developer Portal 中开启。

Q2:Slack Bot 只在 DM 中有效,频道里无反应

需要在 Event Subscriptions 中订阅 message.channels 事件。

Q3:Bot 回复被截断

平台消息长度限制不同。Hermes 会自动分段发送长消息。

Q4:群里 Bot 对每条消息都回复

群组中需要 @提及 才会触发。检查是否配置了「只响应 @提及」模式。


本篇小结

知识点 核心内容
Discord Bot Developer Portal 创建 + Token + Intent
Message Content Intent Discord Bot 必须 开启
Slack App OAuth Scopes + Event Subscriptions
message.channels Slack 公共频道必须订阅
群组触发 Discord/Slack 需要 @提及
平台对比 Telegram 最灵活,Slack 文字上限最高
多平台 可同时运行多个平台

下篇预告

第 13 篇:邮件、短信与其他平台集成

除了即时通讯,Hermes 还能接入邮件、短信和国内平台(飞书/企业微信/钉钉)。下一篇覆盖剩余平台。


如果本篇内容对你有帮助,欢迎点赞收藏!有任何疑问,欢迎在评论区交流。

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐