Agent DiscordBot
A TypeScript CLI tool that enables AI agents and humans to interact with Discord servers using bot tokens. Unlike agent-discord which extracts user tokens from the desktop app, agent-discordbot uses standard Discord Bot tokens for server-side and CI/CD integrations.
Quick Start
CODEBLOCK0
Authentication
Bot Token Setup
agent-discordbot uses Discord Bot tokens which you create in the Discord Developer Portal:
CODEBLOCK1
Getting a Bot Token
- 1. Go to discord.com/developers/applications
- Click New Application, give it a name, and create
- Go to Bot in the left sidebar
- Click Reset Token (or Copy if the token is still visible)
- Copy the token and store it securely
Inviting the Bot to a Server
After creating the application:
- 1. Go to OAuth2 > URL Generator in the left sidebar
- Under Scopes, select INLINECODE0
- Under Bot Permissions, select the permissions your bot needs (Send Messages, Read Message History, etc.)
- Copy the generated URL and open it in your browser
- Select the server and authorize
Message Content Privileged Intent
Bots in 100 or more servers require verification (you can apply once you reach 75+ servers), and verified bots must apply for access to the Message Content intent. Enable it to read message content:
- 1. Go to discord.com/developers/applications
- Select your application
- Go to Bot in the left sidebar
- Under Privileged Gateway Intents, enable Message Content Intent
- Save changes
Without this, verified bots receive empty content fields (DMs and mentions are exempt).
Multi-Bot Management
Store multiple bot tokens and switch between them:
CODEBLOCK2
The --bot <id> flag is available on all commands to override the active bot for a single invocation.
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, etc.) - After discovering useful channel IDs and names (from
channel list, etc.) - After discovering user IDs and names (from
user list, etc.) - After the user gives you an alias or preference ("call this the alerts bot", "my main server is X")
- After setting up bot identifiers (from
auth list)
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
- Bot identifiers and their purposes
- User-given aliases ("alerts bot", "announcements channel")
- Any user preference expressed during interaction
What NOT to Store
Never store bot 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
CODEBLOCK3
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
CODEBLOCK4
Server Commands
CODEBLOCK5
Message Commands
CODEBLOCK6
Channel Commands
CODEBLOCK7
User Commands
CODEBLOCK8
Reaction Commands
CODEBLOCK9
File Commands
CODEBLOCK10
Thread Commands
CODEBLOCK11
Snapshot Command
Get comprehensive server state for AI agents:
CODEBLOCK12
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:
CODEBLOCK13
Pretty (Human-Readable)
Use --pretty flag for formatted output:
CODEBLOCK14
Global Options
| Option | Description |
|---|
| INLINECODE19 | Human-readable output instead of JSON |
| INLINECODE20 |
Use a specific bot for this command |
|
--server <id> | Use a specific server for this command |
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 - INLINECODE25 - Monitor channel for new messages
- INLINECODE26 - Generate server summary
Error Handling
All commands return consistent error format:
CODEBLOCK15
Common errors:
- -
missing_token: No credentials configured - INLINECODE28 : Token is invalid or expired
- INLINECODE29 : Bot lacks permission for this action
- INLINECODE30 : Invalid channel ID
- INLINECODE31 : Bot role doesn't have the required permission
Configuration
Credentials stored in: INLINECODE32
Format:
CODEBLOCK16
Security: File permissions set to 0600 (owner read/write only)
Key Differences from agent-discord
| Feature | agent-discord | agent-discordbot |
|---|
| Token type | User token | Bot token |
| Token source |
Auto-extracted from desktop app | Manual from Developer Portal |
| Message search | Yes | No |
| DMs | Yes | No |
| Mentions | Yes | No |
| Friends/Notes | Yes | No |
| Edit/delete messages | Any message | Bot's own messages only |
| File upload | Yes | Yes |
| Snapshot | Yes | Yes |
| CI/CD friendly | Requires desktop app | Yes (just set token) |
Limitations
- - No real-time events / Gateway connection
- No voice channel support
- No server management (create/delete channels, roles)
- No slash commands
- No webhook support
- No message search
- No DMs or friend management
- Bot can only edit/delete its own messages
- Bot must be invited to the server and have appropriate permissions
- Message Content intent required for verified bots (100+ servers)
- Plain text messages only (no embeds in v1)
Troubleshooting
agent-discordbot: command not found
agent-discordbot is NOT the npm package name. The npm package is agent-messenger.
If the package is installed globally, use agent-discordbot directly:
CODEBLOCK17
If the package is NOT installed, use bunx agent-messenger discordbot:
CODEBLOCK18
NEVER run bunx agent-discordbot -- it will fail or install a wrong package since agent-discordbot is not the npm package name.
Bot can't read messages in large servers
Enable the Message Content Intent in the Developer Portal:
- 1. Go to discord.com/developers/applications
- Select your application > Bot
- Enable Message Content Intent under Privileged Gateway Intents
- Save changes
This is required for verified bots (those in 100 or more servers).
"Missing Access" or "Missing Permissions"
The bot's role doesn't have the required permissions in that channel:
- 1. Check the bot's role permissions in Server Settings > Roles
- Check channel-specific permission overrides
- Make sure the bot can see and send messages in the target channel
"Unknown Channel"
The channel ID is invalid, or the bot doesn't have access to it. Use channel list to find valid channel IDs.
Token expired or invalid
Bot tokens don't expire on their own, but they can be reset:
- 1. Go to discord.com/developers/applications
- Select your application > Bot > Reset Token
- Copy the new token
- Run INLINECODE41
References
Agent DiscordBot
一个TypeScript CLI工具,使AI代理和人类能够使用机器人令牌与Discord服务器交互。与从桌面应用提取用户令牌的agent-discord不同,agent-discordbot使用标准的Discord机器人令牌进行服务器端和CI/CD集成。
快速开始
bash
设置你的机器人令牌
agent-discordbot auth set your-bot-token
验证身份认证
agent-discordbot auth status
发送消息
agent-discordbot message send 1234567890123456789 来自机器人的问候!
列出频道
agent-discordbot channel list
身份认证
机器人令牌设置
agent-discordbot使用你在Discord开发者门户创建的Discord机器人令牌:
bash
设置机器人令牌(保存前会向Discord API验证)
agent-discordbot auth set your-bot-token
使用自定义机器人标识符设置
agent-discordbot auth set your-bot-token --bot deploy --name 部署机器人
检查身份认证状态
agent-discordbot auth status
清除存储的凭据
agent-discordbot auth clear
获取机器人令牌
- 1. 访问 discord.com/developers/applications
- 点击 新建应用,为其命名并创建
- 在左侧边栏进入 机器人
- 点击 重置令牌(如果令牌仍可见则点击 复制)
- 复制令牌并安全存储
邀请机器人到服务器
创建应用后:
- 1. 在左侧边栏进入 OAuth2 > URL生成器
- 在 范围 下,选择 bot
- 在 机器人权限 下,选择机器人需要的权限(发送消息、读取消息历史等)
- 复制生成的URL并在浏览器中打开
- 选择服务器并授权
消息内容特权意图
在100个或更多服务器中的机器人需要验证(当达到75+服务器时可以申请),已验证的机器人必须申请访问消息内容意图。启用它以读取消息内容:
- 1. 访问 discord.com/developers/applications
- 选择你的应用
- 在左侧边栏进入 机器人
- 在 特权网关意图 下,启用 消息内容意图
- 保存更改
没有此设置,已验证的机器人将收到空的 content 字段(私信和提及除外)。
多机器人管理
存储多个机器人令牌并在它们之间切换:
bash
添加多个机器人
agent-discordbot auth set deploy-bot-token --bot deploy --name 部署机器人
agent-discordbot auth set alert-bot-token --bot alert --name 警报机器人
列出所有存储的机器人
agent-discordbot auth list
切换活动机器人
agent-discordbot auth use deploy
对单个命令使用特定机器人(无需切换)
agent-discordbot message send 1234567890123456789 警报! --bot alert
移除存储的机器人
agent-discordbot auth remove deploy
所有命令均可使用 --bot 标志来覆盖单次调用的活动机器人。
记忆
代理维护一个 ~/.config/agent-messenger/MEMORY.md 文件作为跨会话的持久记忆。这是由代理管理的——CLI不会读取或写入此文件。使用 读取 和 写入 工具来管理你的记忆文件。
读取记忆
在 每个任务开始时,使用 读取 工具读取 ~/.config/agent-messenger/MEMORY.md,以加载任何先前发现的服务器ID、频道ID、用户ID和偏好。
- - 如果文件尚不存在,没关系——继续执行,并在首次有有用信息需要存储时创建它。
- 如果文件无法读取(权限问题、缺少目录),在没有记忆的情况下继续——不要报错。
写入记忆
发现有用信息后,使用 写入 工具更新 ~/.config/agent-messenger/MEMORY.md。写入触发条件包括:
- - 发现服务器ID和名称后(来自 server list 等)
- 发现有用的频道ID和名称后(来自 channel list 等)
- 发现用户ID和名称后(来自 user list 等)
- 用户给你别名或偏好后(把这个叫做警报机器人,我的主服务器是X)
- 设置机器人标识符后(来自 auth list)
写入时,包含 完整的文件内容——写入 工具会覆盖整个文件。
存储内容
- - 带名称的服务器ID
- 带名称和分类的频道ID
- 带显示名称的用户ID
- 机器人标识符及其用途
- 用户提供的别名(警报机器人、公告频道)
- 交互过程中表达的任何用户偏好
不存储内容
切勿存储机器人令牌、凭据或任何敏感数据。切勿存储完整的消息内容(仅存储ID和频道上下文)。切勿存储文件上传内容。
处理过时数据
如果记忆的ID返回错误(频道未找到、服务器未找到),将其从 MEMORY.md 中移除。不要盲目信任记忆的数据——当某些内容看起来不对时进行验证。优先重新列出,而不是使用可能过时的记忆ID。
格式/示例
markdown
代理信使记忆
Discord服务器(机器人)
- - 1234567890123456 — Acme开发
机器人(Acme开发)
- - deploy — 部署机器人(活动)
- alert — 警报机器人
频道(Acme开发)
- - 1111111111111111 — #通用(通用分类)
- 2222222222222222 — #工程(工程分类)
- 3333333333333333 — #部署(工程分类)
用户(Acme开发)
- - 4444444444444444 — 爱丽丝(服务器所有者)
- 5555555555555555 — 鲍勃
别名
- - 部署 → 3333333333333333(Acme开发中的#部署)
备注
- - 部署机器人用于CI/CD通知
- 警报机器人用于错误监控
记忆让你可以跳过重复的 channel list 和 server list 调用。当你已经从之前的会话中知道某个ID时,直接使用它。
命令
身份认证命令
bash
设置机器人令牌
agent-discordbot auth set
agent-discordbot auth set --bot deploy --name 部署机器人
检查身份认证状态
agent-discordbot auth status
清除所有凭据
agent-discordbot auth clear
列出存储的机器人
agent-discordbot auth list
切换活动机器人
agent-discordbot auth use
移除存储的机器人
agent-discordbot auth remove
服务器命令
bash
列出机器人所在的服务器
agent-discordbot server list
显示当前服务器
agent-discordbot server current
切换活动服务器
agent-discordbot server switch
获取服务器信息
agent-discordbot server info
消息命令
bash
发送消息
agent-discordbot message send
agent-discordbot message send 1234567890123456789 你好世界
列出消息
agent-discordbot message list
agent-discordbot message list 1234567890123456789 --limit 50
按ID获取单条消息
agent-discordbot message get
获取线程回复
agent-discordbot message replies
agent-discordbot message replies 1234567890123456789 9876543210987654321 --limit 50
更新消息(仅限机器人自己的消息)
agent-discordbot message update
删除消息(仅限机器人自己的消息)
agent-discordbot message delete --force
频道命令
bash
列出当前服务器中的频道
agent-discordbot channel list
获取频道信息
agent-discordbot channel info
agent-discordbot channel info 1234567890123456789
用户命令
bash
列出服务器成员
agent-discordbot user list
agent-discordbot user list --limit 50
获取用户信息
agent-discordbot user info
反应命令
bash
添加反应(使用表情符号名称,不带冒号)
agent-discordbot reaction add
agent-discordbot reaction add 1234567890123456789 9876543210987654321 thumbsup
移除反应
agent-discord