与Discord服务器交互 - 发送消息、读取频道、管理反应
Agent Discord: 1,A TypeScript CLI工具,它使AI代理和人类能够通过简单的命令界面与Discord服务器交互.是一项面向实际任务的技能,主要用于Features super signition from Discord d。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;
涉及批量任务时,还应保存进度,避免中断后重复操作。该技能适合用于一次性任务,也可以接入自动化工作流,与其他技能或上层代理配合完成更完整的业务链路;在组合使用时,应明确每一步的输入输出关系,并避免不同步骤之间出现参数冲突。
一款 TypeScript 编写的命令行工具(CLI),支持 AI 智能体与人类通过简洁的命令接口与 Discord 服务器进行交互。具备从 Discord 桌面客户端自动提取认证凭据、多服务器切换等特性。
# 获取服务器快照(凭据将自动提取) agent-discord snapshot # 发送消息 agent-discord message send"Hello from AI agent!" # 列出频道 agent-discord channel list
首次使用时,凭据会自动从本地 Discord 桌面客户端中提取。无需手动配置——只需运行任意命令,认证将在后台静默完成。
在 macOS 系统上,首次运行时系统可能会提示输入 Keychain 密码(用于解密 Discord 存储的 token)。该提示仅出现一次。
重要提示:切勿引导用户打开网页浏览器、使用 DevTools 或手动从浏览器中复制 token。始终使用 agent-discord auth extract 命令从桌面客户端提取 token。
# 列出所有可用服务器 agent-discord server list # 切换至其他服务器 agent-discord server switch# 显示当前服务器 agent-discord server current # 查看认证状态 agent-discord auth status
智能体通过维护 ~/.config/agent-messenger/MEMORY.md 文件实现跨会话的持久化记忆。该文件由智能体自主管理——CLI 工具本身不读取或写入此文件。请使用 Read 和 Write 工具来管理该记忆文件。
在每个任务开始时,请务必使用 Read 工具读取 ~/.config/agent-messenger/MEMORY.md,以加载此前已发现的服务器 ID、频道 ID、用户 ID 及用户偏好设置等信息。
在发现有价值的信息后,请使用 Write 工具更新 ~/.config/agent-messenger/MEMORY.md。典型写入场景包括:
server list、snapshot 等命令获取服务器 ID 及名称后channel list、snapshot 等命令获取有用频道 ID 及名称后user list、user me 等命令获取用户 ID 及名称后写入时需提供完整的文件内容——Write 工具将覆盖整个文件。
严禁存储 token、凭据或任何敏感数据;严禁存储完整的消息正文(仅可记录 ID 及频道上下文);严禁存储文件上传内容。
若某条已记忆的 ID 返回错误(如“频道未找到”、“服务器未找到”),请立即从 MEMORY.md 中移除该条目。切勿盲目信任记忆中的数据——当结果异常时,请主动验证。在存疑情况下,优先重新执行 list 类命令,而非依赖可能已过期的记忆 ID。
# Agent Messenger Memory ## Discord Servers - `1234567890123456` — Acme Dev (default) - `9876543210987654` — Open Source Community ## Channels (Acme Dev) - `1111111111111111` — #general (General category) - `2222222222222222` — #engineering (Engineering category) - `3333333333333333` — #deploys (Engineering category) ## Users (Acme Dev) - `4444444444444444` — Alice (server owner) - `5555555555555555` — Bob ## Aliases - "dev server" → `1234567890123456` (Acme Dev) - "deploys" → `3333333333333333` (#deploys in Acme Dev) ## Notes - User prefers --pretty output for snapshots - Main server is "Acme Dev"
记忆机制使你可跳过重复的
channel list和server list调用。当你已在前序会话中获知某个 ID 时,可直接使用它。
# 从 Discord 桌面客户端提取 token(通常自动完成) agent-discord auth extract agent-discord auth extract --debug # 查看认证状态 agent-discord auth status # 退出 Discord 登录 agent-discord auth logout
# 发送消息 agent-discord message sendagent-discord message send 1234567890123456789 "Hello world" # 列出频道中的消息 agent-discord message list agent-discord message list 1234567890123456789 --limit 50 # 根据 ID 获取单条消息 agent-discord message get agent-discord message get 1234567890123456789 9876543210987654321 # 删除消息 agent-discord message delete --force # 标记消息为已读(acknowledge) agent-discord message ack # 在当前服务器中搜索消息 agent-discord message search agent-discord message search "project update" --limit 10 agent-discord message search "hello" --channel --author
# 列出当前服务器中的频道(仅限文字频道) agent-discord channel list # 获取频道详情 agent-discord channel infoagent-discord channel info 1234567890123456789 # 获取频道历史(等同于 message list) agent-discord channel history --limit 100
# 列出所有服务器 agent-discord server list # 获取服务器详情 agent-discord server info# 切换当前活跃服务器 agent-discord server switch # 显示当前服务器 agent-discord server current
# 列出服务器成员 agent-discord user list # 获取用户详情 agent-discord user info# 获取当前用户信息 agent-discord user me
# 列出私信频道 agent-discord dm list # 与指定用户创建私信频道 agent-discord dm create
# 列出最近的提及 agent-discord mention list agent-discord mention list --limit 50 agent-discord mention list --guild
# 列出所有关系(好友、被屏蔽、待处理请求) agent-discord friend list agent-discord friend list --pretty
# 获取某用户的备注 agent-discord note get# 设置某用户的备注 agent-discord note set "Note content"
# 获取详细用户资料 agent-discord profile get
# 搜索服务器成员 agent-discord member searchagent-discord member search 1234567890123456789 "john" --limit 20
# 在频道中创建线程 agent-discord thread createagent-discord thread create 1234567890123456789 "Discussion" --auto-archive-duration 1440 # 归档线程 agent-discord thread archive
# 添加表情反应(使用 emoji 名称,无需冒号) agent-discord reaction addagent-discord reaction add 1234567890123456789 9876543210987654321 thumbsup # 移除表情反应 agent-discord reaction remove # 列出某条消息上的所有反应 agent-discord reaction list
# 上传文件 agent-discord file uploadagent-discord file upload 1234567890123456789 ./report.pdf # 列出频道中的文件 agent-discord file list # 获取文件详情 agent-discord file info
为 AI 智能体获取全面的服务器状态:
# 完整快照 agent-discord snapshot # 过滤式快照 agent-discord snapshot --channels-only agent-discord snapshot --users-only # 限制每频道返回的消息数量 agent-discord snapshot --limit 10
返回包含以下字段的 JSON:
所有命令默认输出 JSON 格式,便于 AI 解析消费:
{
"id": "1234567890123456789",
"content": "Hello world",
"author": "username",
"timestamp": "2024-01-15T10:30:00.000Z"
}
使用 --pretty 参数可获得格式化输出:
agent-discord channel list --pretty
| 特性 | Discord | Slack |
|---|---|---|
| 服务器术语 | Server | Workspace |
| 频道标识符 | Snowflake ID | 频道名称或 ID |
| 消息标识符 | Snowflake ID | 时间戳(ts) |
| 线程(Thread) | Thread ID 字段 | 线程时间戳 |
| 提及(Mention) | <@user_id> |
<@USER_ID> |
重要提示:Discord 所有标识符均采用 Snowflake ID(形如 1234567890123456789 的大整数)。不可直接使用频道名称——请先通过 channel list 查询对应 ID。
参见 references/common-patterns.md 查看典型的 AI 智能体工作流。
参见 templates/ 目录下的可运行示例:
post-message.sh —— 带错误处理的消息发送脚本monitor-channel.sh —— 监控频道新消息的脚本server-summary.sh —— 生成服务器摘要的脚本所有命令均返回统一格式的错误响应:
{
"error": "Not authenticated. Run "auth extract" first."
}
常见错误类型:
Not authenticated:无有效 token(自动提取失败——详见故障排查章节)No current server set:尚未设置当前服务器,请先运行 server switch Message not found:消息 ID 无效Unknown Channel:频道 ID 无效凭据存储路径:~/.config/agent-messenger/discord-credentials.json
文件格式示例:
{
"token": "user_token_here",
"current_server": "1234567890123456789",
"servers": {
"1234567890123456789": {
"server_id": "1234567890123456789",
"server_name": "My Server"
}
}
}
安全性:该文件权限设为 0600(仅属主可读写)
凭据通常自动提取。若自动提取失败,请手动执行并启用调试输出:
agent-discord auth extract --debug
常见原因:
agent-discord: command not foundagent-discord 并非 npm 包名。 对应的 npm 包名为 agent-messenger。
若已全局安装该包,可直接使用 agent-discord:
agent-discord server list
若尚未安装该包,请使用 bunx agent-messenger discord:
bunx agent-messenger discord server list
切勿运行 bunx agent-discord —— 因 agent-discord 并非合法的 npm 包名,该命令将失败或安装错误的包。