discord
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDiscord Bot API
Discord Bot API
Use the Discord Bot API via direct calls to manage channels, guilds, messages, and users.
curlOfficial docs:https://discord.com/developers/docs
通过直接调用来使用Discord Bot API,以管理频道、服务器、消息和用户。
curl官方文档:https://discord.com/developers/docs
When to Use
适用场景
Use this skill when you need to:
- Send messages to specific channels
- Read messages from channels
- Manage channels (create, edit, delete)
- Get server info (guilds, members, roles)
- React to messages and moderate content
- Create webhooks programmatically
For simple message posting, use skill instead.
discord-webhook当你需要以下操作时,可以使用此技能:
- 给指定频道发送消息
- 从频道读取消息
- 管理频道(创建、编辑、删除)
- 获取服务器信息(服务器、成员、角色)
- 对消息添加反应并管理内容
- 以编程方式创建Webhook
如果只是简单发送消息,建议使用技能。
discord-webhookPrerequisites
前置条件
1. Create Application
1. 创建应用
- Go to Discord Developer Portal
- Click "New Application" and give it a name
- Go to "Bot" section and click "Add Bot"
- 访问Discord开发者平台
- 点击「新建应用」并为其命名
- 进入「机器人」板块,点击「添加机器人」
2. Get Bot Token
2. 获取机器人令牌
- In Bot section, click "Reset Token"
- Copy the token (shown only once)
bash
export DISCORD_BOT_TOKEN="MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.ABcDeF.xxxxx..."- 在机器人板块中,点击「重置令牌」
- 复制令牌(仅显示一次)
bash
export DISCORD_BOT_TOKEN="MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.ABcDeF.xxxxx..."3. Enable Intents (if needed)
3. 启用意图(如有需要)
In Bot section, enable:
- Presence Intent (for user status)
- Server Members Intent (for member list)
- Message Content Intent (for reading messages)
在机器人板块中,启用:
- Presence Intent(用于获取用户在线状态)
- Server Members Intent(用于获取成员列表)
- Message Content Intent(用于读取消息内容)
4. Invite Bot to Server
4. 将机器人邀请至服务器
- Go to OAuth2 → URL Generator
- Select scopes: ,
botapplications.commands - Select permissions needed (e.g., Send Messages, Read Messages)
- Copy URL and open in browser to invite
- 进入OAuth2 → URL生成器
- 选择权限范围:、
botapplications.commands - 选择所需权限(例如:发送消息、读取消息)
- 复制链接并在浏览器中打开,完成机器人邀请
5. Get IDs
5. 获取ID
Enable Developer Mode: User Settings → Advanced → Developer Mode
Right-click any channel/user/server → Copy ID
Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .
开启开发者模式:用户设置 → 高级 → 开发者模式
右键点击任意频道/用户/服务器 → 复制ID
重要提示: 当在包含管道的命令中使用时,请将包含$VAR的命令用$VAR包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清除。bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .
How to Use
使用方法
Base URL:
https://discord.com/api/v10Authorization header:
Authorization: Bot YOUR_TOKEN基础URL:
https://discord.com/api/v10授权头:
Authorization: Bot 你的令牌1. Get Current Bot User
1. 获取当前机器人用户
bash
bash -c 'curl -s "https://discord.com/api/v10/users/@me" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, username, discriminator}'bash
bash -c 'curl -s "https://discord.com/api/v10/users/@me" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, username, discriminator}'2. Send Message to Channel
2. 给频道发送消息
Write to :
/tmp/discord_request.jsonjson
{
"content": "Hello from bot!"
}Then run (replace with the actual channel ID):
<your-channel-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/channels/<your-channel-id>/messages" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json'写入内容到:
/tmp/discord_request.jsonjson
{
"content": "来自机器人的问候!"
}然后执行命令(将替换为实际的频道ID):
<your-channel-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/channels/<your-channel-id>/messages" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json'3. Send Embed Message
3. 发送嵌入消息
Write to :
/tmp/discord_request.jsonjson
{
"embeds": [
{
"title": "Bot Message",
"description": "This is from the bot API",
"color": 5793266
}
]
}Then run (replace with the actual channel ID):
<your-channel-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/channels/<your-channel-id>/messages" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json'写入内容到:
/tmp/discord_request.jsonjson
{
"embeds": [
{
"title": "机器人消息",
"description": "这是通过Bot API发送的消息",
"color": 5793266
}
]
}然后执行命令(将替换为实际的频道ID):
<your-channel-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/channels/<your-channel-id>/messages" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json'4. Get Channel Info
4. 获取频道信息
Replace with the actual channel ID:
<your-channel-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, name, type, guild_id}'将替换为实际的频道ID:
<your-channel-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, name, type, guild_id}'5. Get Channel Messages
5. 获取频道消息
Replace with the actual channel ID:
<your-channel-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>/messages?limit=10" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, author: .author.username, content}'将替换为实际的频道ID:
<your-channel-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>/messages?limit=10" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, author: .author.username, content}'6. Get Specific Message
6. 获取指定消息
Replace and with the actual IDs:
<your-channel-id><your-message-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>/messages/<your-message-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, content, author: .author.username}'将和替换为实际的ID:
<your-channel-id><your-message-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>/messages/<your-message-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, content, author: .author.username}'7. Delete Message
7. 删除消息
Replace and with the actual IDs:
<your-channel-id><your-message-id>bash
bash -c 'curl -s -X DELETE "https://discord.com/api/v10/channels/<your-channel-id>/messages/<your-message-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"'将和替换为实际的ID:
<your-channel-id><your-message-id>bash
bash -c 'curl -s -X DELETE "https://discord.com/api/v10/channels/<your-channel-id>/messages/<your-message-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"'8. Add Reaction
8. 添加消息反应
Replace and with the actual IDs:
<your-channel-id><your-message-id>bash
bash -c 'curl -s -X PUT "https://discord.com/api/v10/channels/<your-channel-id>/messages/<your-message-id>/reactions/%F0%9F%91%8D/@me" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Length: 0"'Note: Emoji must be URL encoded (👍 = )
%F0%9F%91%8D将和替换为实际的ID:
<your-channel-id><your-message-id>bash
bash -c 'curl -s -X PUT "https://discord.com/api/v10/channels/<your-channel-id>/messages/<your-message-id>/reactions/%F0%9F%91%8D/@me" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Length: 0"'注意:表情符号必须进行URL编码(👍 = )
%F0%9F%91%8D9. Get Guild (Server) Info
9. 获取服务器信息
Replace with the actual guild ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, name, member_count, owner_id}'将替换为实际的服务器ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '{id, name, member_count, owner_id}'10. List Guild Channels
10. 列出服务器频道
Replace with the actual guild ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>/channels" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, name, type}'将替换为实际的服务器ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>/channels" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, name, type}'11. Get Guild Members
11. 获取服务器成员
Replace with the actual guild ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>/members?limit=10" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {user: .user.username, nick, joined_at}'将替换为实际的服务器ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>/members?limit=10" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {user: .user.username, nick, joined_at}'12. Get Guild Roles
12. 获取服务器角色
Replace with the actual guild ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>/roles" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, name, color, position}'将替换为实际的服务器ID:
<your-guild-id>bash
bash -c 'curl -s "https://discord.com/api/v10/guilds/<your-guild-id>/roles" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, name, color, position}'13. Create Webhook
13. 创建Webhook
Write to :
/tmp/discord_request.jsonjson
{
"name": "My Webhook"
}Then run (replace with the actual channel ID):
<your-channel-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/channels/<your-channel-id>/webhooks" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json' | jq '{id, token, url: "https://discord.com/api/webhooks/\(.id)/\(.token)"}'写入内容到:
/tmp/discord_request.jsonjson
{
"name": "我的Webhook"
}然后执行命令(将替换为实际的频道ID):
<your-channel-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/channels/<your-channel-id>/webhooks" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json' | jq '{id, token, url: "https://discord.com/api/webhooks/\(.id)/\(.token)"}'14. List Channel Webhooks
14. 列出频道Webhook
Replace with the actual channel ID:
<your-channel-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>/webhooks" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, name, token}'将替换为实际的频道ID:
<your-channel-id>bash
bash -c 'curl -s "https://discord.com/api/v10/channels/<your-channel-id>/webhooks" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}"' | jq '.[] | {id, name, token}'15. Create Text Channel
15. 创建文本频道
Write to :
/tmp/discord_request.jsonjson
{
"name": "new-channel",
"type": 0
}Then run (replace with the actual guild ID):
<your-guild-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/guilds/<your-guild-id>/channels" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json' | jq '{id, name}'写入内容到:
/tmp/discord_request.jsonjson
{
"name": "new-channel",
"type": 0
}然后执行命令(将替换为实际的服务器ID):
<your-guild-id>bash
bash -c 'curl -s -X POST "https://discord.com/api/v10/guilds/<your-guild-id>/channels" -H "Authorization: Bot ${DISCORD_BOT_TOKEN}" -H "Content-Type: application/json" -d @/tmp/discord_request.json' | jq '{id, name}'Channel Types
频道类型
| Type | Description |
|---|---|
| 0 | Text channel |
| 2 | Voice channel |
| 4 | Category |
| 5 | Announcement |
| 13 | Stage |
| 15 | Forum |
| 类型 | 描述 |
|---|---|
| 0 | 文本频道 |
| 2 | 语音频道 |
| 4 | 分类频道 |
| 5 | 公告频道 |
| 13 | 舞台频道 |
| 15 | 论坛频道 |
Guidelines
注意事项
- Rate limits: Check headers; implement backoff
X-RateLimit-* - Token security: Never expose bot tokens
- Permissions: Bot needs appropriate permissions for each action
- Intents: Enable required intents in Developer Portal
- API version: Use for latest stable API
/v10
- 速率限制:检查响应头;实现退避机制
X-RateLimit-* - 令牌安全:切勿泄露机器人令牌
- 权限设置:机器人需要具备对应操作的权限
- 意图配置:在开发者平台启用所需的意图
- API版本:使用作为最新稳定版API
/v10