Agent Discord
A TypeScript CLI tool that enables AI agents and humans to interact with Discord servers through a simple command interface. Features seamless token extraction from the Discord desktop app and multi-server support.
Quick Start
CODEBLOCK0
Authentication
Credentials are extracted automatically from the Discord desktop app on first use. No manual setup required — just run any command and authentication happens silently in the background.
On macOS, the system may prompt for your Keychain password the first time (required to decrypt Discord's stored token). This is a one-time prompt.
IMPORTANT: NEVER guide the user to open a web browser, use DevTools, or manually copy tokens from a browser. Always use agent-discord auth extract to obtain tokens from the desktop app.
Multi-Server Support
CODEBLOCK1
Memory
The agent maintains a ~/.config/agent-messenger/MEMORY.md file as persistent memory across sessions. This is agent-managed — the CLI does not read or write this file. Use the Read and Write tools to manage your memory file.
Reading Memory
At the start of every task, read ~/.config/agent-messenger/MEMORY.md using the Read tool to load any previously discovered server IDs, channel IDs, user IDs, and preferences.
- - If the file doesn't exist yet, that's fine — proceed without it and create it when you first have useful information to store.
- If the file can't be read (permissions, missing directory), proceed without memory — don't error out.
Writing Memory
After discovering useful information, update ~/.config/agent-messenger/MEMORY.md using the Write tool. Write triggers include:
- - After discovering server IDs and names (from
server list, snapshot, etc.) - After discovering useful channel IDs and names (from
channel list, snapshot, etc.) - After discovering user IDs and names (from
user list, user me, etc.) - After the user gives you an alias or preference ("call this the dev server", "my main channel is X")
- After discovering channel structure (categories, voice channels)
When writing, include the complete file content — the Write tool overwrites the entire file.
What to Store
- - Server IDs with names
- Channel IDs with names and categories
- User IDs with display names
- User-given aliases ("dev server", "announcements channel")
- Commonly used thread IDs
- Any user preference expressed during interaction
What NOT to Store
Never store tokens, credentials, or any sensitive data. Never store full message content (just IDs and channel context). Never store file upload contents.
Handling Stale Data
If a memorized ID returns an error (channel not found, server not found), remove it from MEMORY.md. Don't blindly trust memorized data — verify when something seems off. Prefer re-listing over using a memorized ID that might be stale.
Format / Example
CODEBLOCK2
Memory lets you skip repeated channel list and server list calls. When you already know an ID from a previous session, use it directly.
Commands
Auth Commands
CODEBLOCK3
Message Commands
CODEBLOCK4
Channel Commands
CODEBLOCK5
Server Commands
CODEBLOCK6
User Commands
CODEBLOCK7
DM Commands
CODEBLOCK8
Mention Commands
CODEBLOCK9
Friend Commands
CODEBLOCK10
Note Commands
CODEBLOCK11
Profile Commands
CODEBLOCK12
Member Commands
CODEBLOCK13
Thread Commands
CODEBLOCK14
Reaction Commands
CODEBLOCK15
File Commands
CODEBLOCK16
Snapshot Command
Get comprehensive server state for AI agents:
CODEBLOCK17
Returns JSON with:
- - Server metadata (id, name)
- Channels (id, name, type, topic)
- Recent messages (id, content, author, timestamp)
- Members (id, username, global_name)
Output Format
JSON (Default)
All commands output JSON by default for AI consumption:
CODEBLOCK18
Pretty (Human-Readable)
Use --pretty flag for formatted output:
CODEBLOCK19
Key Differences from Slack
| Feature | Discord | Slack |
|---|
| Server terminology | Server | Workspace |
| Channel identifiers |
Snowflake IDs | Channel name or ID |
| Message identifiers | Snowflake IDs | Timestamps (ts) |
| Threads | Thread ID field | Thread timestamp |
| Mentions |
<@user_id> |
<@USER_ID> |
Important: Discord uses Snowflake IDs (large numbers like 1234567890123456789) for all identifiers. You cannot use channel names directly - use channel list to find IDs first.
Common Patterns
See references/common-patterns.md for typical AI agent workflows.
Templates
See templates/ directory for runnable examples:
- -
post-message.sh - Send messages with error handling - INLINECODE26 - Monitor channel for new messages
- INLINECODE27 - Generate server summary
Error Handling
All commands return consistent error format:
CODEBLOCK20
Common errors:
- -
Not authenticated: No valid token (auto-extraction failed — see Troubleshooting) - INLINECODE29 : Run
server switch <id> first - INLINECODE31 : Invalid message ID
- INLINECODE32 : Invalid channel ID
Configuration
Credentials stored in: INLINECODE33
Format:
CODEBLOCK21
Security: File permissions set to 0600 (owner read/write only)
Limitations
- - No real-time events / Gateway connection
- No voice channel support
- No server management (create/delete channels, roles)
- No slash commands
- No webhook support
- Plain text messages only (no embeds in v1)
- User tokens only (no bot tokens)
Troubleshooting
Authentication fails or no token found
Credentials are normally extracted automatically. If auto-extraction fails, run it manually with debug output:
CODEBLOCK22
Common causes:
- - Discord desktop app is not installed or not logged in
- macOS Keychain access was denied (re-run and approve the prompt)
- Discord is not running and LevelDB files are stale
agent-discord: command not found
agent-discord is NOT the npm package name. The npm package is agent-messenger.
If the package is installed globally, use agent-discord directly:
CODEBLOCK23
If the package is NOT installed, use bunx agent-messenger discord:
CODEBLOCK24
NEVER run bunx agent-discord — it will fail or install a wrong package since agent-discord is not the npm package name.
References
Agent Discord
一个TypeScript CLI工具,使AI智能体和人类能够通过简单的命令界面与Discord服务器交互。支持从Discord桌面应用无缝提取令牌,并支持多服务器管理。
快速开始
bash
获取服务器快照(凭据自动提取)
agent-discord snapshot
发送消息
agent-discord message send <频道ID> 来自AI智能体的问候!
列出频道
agent-discord channel list
身份认证
首次使用时,凭据会自动从Discord桌面应用中提取。无需手动设置——只需运行任意命令,身份认证就会在后台静默完成。
在macOS上,系统可能会在首次使用时提示输入钥匙串密码(用于解密Discord存储的令牌)。这是一次性提示。
重要提示:切勿引导用户打开网页浏览器、使用开发者工具或手动从浏览器复制令牌。始终使用agent-discord auth extract从桌面应用获取令牌。
多服务器支持
bash
列出所有可用服务器
agent-discord server list
切换到其他服务器
agent-discord server switch <服务器ID>
显示当前服务器
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。写入触发条件包括:
- - 发现服务器ID和名称后(来自server list、snapshot等)
- 发现有用的频道ID和名称后(来自channel list、snapshot等)
- 发现用户ID和名称后(来自user list、user me等)
- 用户为您提供别名或偏好后(把这个叫开发服务器、我的主频道是X)
- 发现频道结构后(分类、语音频道)
写入时,请包含完整的文件内容——Write工具会覆盖整个文件。
存储内容
- - 带名称的服务器ID
- 带名称和分类的频道ID
- 带显示名称的用户ID
- 用户提供的别名(开发服务器、公告频道)
- 常用的线程ID
- 交互过程中表达的任何用户偏好
禁止存储内容
切勿存储令牌、凭据或任何敏感数据。切勿存储完整的消息内容(仅存储ID和频道上下文)。切勿存储文件上传内容。
处理过期数据
如果记忆中的ID返回错误(频道未找到、服务器未找到),请从MEMORY.md中删除。不要盲目信任记忆的数据——当发现异常时进行验证。优先重新列出,而不是使用可能过期的记忆ID。
格式/示例
markdown
Agent Messenger 记忆
Discord 服务器
- - 1234567890123456 — Acme Dev(默认)
- 9876543210987654 — 开源社区
频道(Acme Dev)
- - 1111111111111111 — #general(通用分类)
- 2222222222222222 — #engineering(工程分类)
- 3333333333333333 — #deploys(工程分类)
用户(Acme Dev)
- - 4444444444444444 — Alice(服务器所有者)
- 5555555555555555 — Bob
别名
- - 开发服务器 → 1234567890123456(Acme Dev)
- 部署频道 → 3333333333333333(Acme Dev中的#deploys)
备注
- - 用户偏好快照使用--pretty输出
- 主服务器是Acme Dev
记忆功能让您无需重复调用channel list和server list。当您已经从之前的会话中知道某个ID时,可以直接使用它。
命令
认证命令
bash
从Discord桌面应用提取令牌(通常自动完成)
agent-discord auth extract
agent-discord auth extract --debug
检查认证状态
agent-discord auth status
登出Discord
agent-discord auth logout
消息命令
bash
发送消息
agent-discord message send <频道ID> <内容>
agent-discord message send 1234567890123456789 你好世界
列出消息
agent-discord message list <频道ID>
agent-discord message list 1234567890123456789 --limit 50
按ID获取单条消息
agent-discord message get <频道ID> <消息ID>
agent-discord message get 1234567890123456789 9876543210987654321
删除消息
agent-discord message delete <频道ID> <消息ID> --force
确认/标记消息为已读
agent-discord message ack <频道ID> <消息ID>
在当前服务器搜索消息
agent-discord message search <查询>
agent-discord message search 项目更新 --limit 10
agent-discord message search 你好 --channel <频道ID> --author <用户ID>
频道命令
bash
列出当前服务器中的频道(仅文本频道)
agent-discord channel list
获取频道信息
agent-discord channel info <频道ID>
agent-discord channel info 1234567890123456789
获取频道历史(message list的别名)
agent-discord channel history <频道ID> --limit 100
服务器命令
bash
列出所有服务器
agent-discord server list
获取服务器信息
agent-discord server info <服务器ID>
切换活动服务器
agent-discord server switch <服务器ID>
显示当前服务器
agent-discord server current
用户命令
bash
列出服务器成员
agent-discord user list
获取用户信息
agent-discord user info <用户ID>
获取当前用户
agent-discord user me
私信命令
bash
列出私信频道
agent-discord dm list
与用户创建私信频道
agent-discord dm create <用户ID>
提及命令
bash
列出最近的提及
agent-discord mention list
agent-discord mention list --limit 50
agent-discord mention list --guild <服务器ID>
好友命令
bash
列出所有关系(好友、已屏蔽、待处理请求)
agent-discord friend list
agent-discord friend list --pretty
备注命令
bash
获取用户备注
agent-discord note get <用户ID>
设置用户备注
agent-discord note set <用户ID> 备注内容
个人资料命令
bash
获取详细的用户个人资料
agent-discord profile get <用户ID>
成员命令
bash
搜索服务器成员
agent-discord member search <服务器ID> <查询>
agent-discord member search 1234567890123456789 张三 --limit 20
线程命令
bash
在频道中创建线程
agent-discord thread create <频道ID> <名称>
agent-discord thread create 1234567890123456789 讨论 --auto-archive-duration 1440
归档线程
agent-discord thread archive <线程ID>
反应命令
bash
添加反应(使用表情符号名称,不带冒号)
agent-discord reaction add <频道ID> <消息ID> <表情>
agent-discord reaction add 1234567890123456789 9876543210987654321 thumbsup
移除反应
agent-discord reaction remove <频道ID> <消息ID> <表情>
列出消息上的反应
agent-discord reaction list <频道ID> <消息ID>
文件命令
bash
上传文件
agent-discord file upload <频道ID> <路径>
agent-discord file upload 1234567890123456789 ./report.pdf
列出频道中的文件
agent-discord file list <频道ID>
获取文件信息
agent-discord file info <频道ID> <文件ID>
快照命令
获取AI智能体所需的完整服务器状态:
bash
完整快照
agent-discord snapshot
筛选快照
agent-discord snapshot --channels-only
agent-discord snapshot --users-only
限制每个频道的消息