discordbot
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWe drive the Discord API
with using the user's bot token in . The
auth header is — note the literal
prefix (NOT ). Base URL is .
curl + jq$DISCORDBOT_TOKENAuthorization: Bot $DISCORDBOT_TOKENBot Bearerhttps://discord.com/api/v10This acts as the user's registered bot, so it can only see and act in
servers (guilds) the bot has been invited to and only where it has the
relevant permission (View Channels / Send Messages / Read Message History).
A (code 50001 "Missing Access" / 50013 "Missing
Permissions") almost always means the bot isn't in that server or lacks the
permission — tell the user to invite the bot or grant the permission rather
than retrying.
403 ForbiddenErrors are JSON . A means the
bot token is wrong/reset — ask the user to re-paste it at
. A carries
(seconds) — sleep that long, then retry; never parallelize.
{"code": <n>, "message": "<reason>"}401auth.acedata.cloud/user/connections429retry_afterBefore sending a message, confirm the exact channel and content with the
user. Sending is irreversible and public to that channel.
我们借助用户存储在中的bot令牌,通过调用Discord API
请求头的认证信息为——注意这里需要字面的前缀(不是)。基础URL为。
$DISCORDBOT_TOKENcurl + jqAuthorization: Bot $DISCORDBOT_TOKENBot Bearerhttps://discord.com/api/v10此操作代表用户已注册的bot执行,因此它只能查看和操作已受邀加入的服务器(guilds),且仅在拥有相关权限(查看频道/发送消息/读取消息历史)的范围内进行。若返回错误(错误码50001“缺少访问权限”/50013“缺少权限”),几乎总是意味着Bot未加入该服务器或缺少对应权限——此时应告知用户邀请Bot或授予相应权限,而非重试请求。
403 Forbidden错误信息为JSON格式。若返回错误,说明Bot令牌错误或已重置——请用户前往重新粘贴令牌。若返回错误,响应中会包含(秒数)——需等待对应时长后重试,切勿并行请求。
{"code": <n>, "message": "<reason>"}401auth.acedata.cloud/user/connections429retry_after**发送消息前,请与用户确认准确的频道和消息内容。**消息一旦发送便不可撤回,且对该频道内所有成员可见。
Recipes
操作示例
Verify the bot (always run first)
验证Bot身份(务必先执行此步骤)
sh
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/users/@me" \
| jq '{id, username, bot}'sh
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/users/@me" \
| jq '{id, username, bot}'List servers (guilds) the bot is in
列出Bot已加入的服务器(guilds)
sh
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/users/@me/guilds" \
| jq 'map({id, name})'sh
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/users/@me/guilds" \
| jq 'map({id, name})'List text channels in a server
列出服务器内的文本频道
Channel 0 = text, 5 = announcement; 2 = voice, 4 = category (skip
those for messaging). You need a guild id from the call above.
typesh
GUILD_ID="123456789012345678"
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/guilds/$GUILD_ID/channels" \
| jq 'map(select(.type==0 or .type==5) | {id, name, type})'频道值为0代表文本频道,5代表公告频道;2为语音频道,4为分类频道(发送消息时可跳过这些类型)。你需要从上述调用中获取服务器ID(guild id)。
typesh
GUILD_ID="123456789012345678"
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/guilds/$GUILD_ID/channels" \
| jq 'map(select(.type==0 or .type==5) | {id, name, type})'Read recent messages in a channel
读取频道内的最新消息
Reading message content requires the Message Content Intent to be
enabled on the bot (Developer Portal → Bot → Privileged Gateway Intents).
Without it, comes back empty for messages that don't mention the
bot. Needs the Read Message History permission in that channel.
contentsh
CHANNEL_ID="123456789012345678"
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/channels/$CHANNEL_ID/messages?limit=20" \
| jq 'map({author: .author.username, ts: .timestamp, content})'读取消息内容需要在Bot设置中启用Message Content Intent(开发者门户→Bot→特权网关意图)。若未启用,对于未提及Bot的消息,字段会返回空值。此外,Bot需要拥有该频道的读取消息历史权限。
contentsh
CHANNEL_ID="123456789012345678"
curl -sS -H "Authorization: Bot $DISCORDBOT_TOKEN" \
"https://discord.com/api/v10/channels/$CHANNEL_ID/messages?limit=20" \
| jq 'map({author: .author.username, ts: .timestamp, content})'Send a message to a channel
向频道发送消息
sh
CHANNEL_ID="123456789012345678"
curl -sS -X POST \
-H "Authorization: Bot $DISCORDBOT_TOKEN" \
-H "Content-Type: application/json" \
"https://discord.com/api/v10/channels/$CHANNEL_ID/messages" \
-d "$(jq -nc --arg c "Hello from the bot." '{content: $c}')"sh
CHANNEL_ID="123456789012345678"
curl -sS -X POST \
-H "Authorization: Bot $DISCORDBOT_TOKEN" \
-H "Content-Type: application/json" \
"https://discord.com/api/v10/channels/$CHANNEL_ID/messages" \
-d "$(jq -nc --arg c "Hello from the bot." '{content: $c}')"Reply to a specific message
回复特定消息
sh
CHANNEL_ID="123456789012345678"; MESSAGE_ID="987654321098765432"
curl -sS -X POST \
-H "Authorization: Bot $DISCORDBOT_TOKEN" \
-H "Content-Type: application/json" \
"https://discord.com/api/v10/channels/$CHANNEL_ID/messages" \
-d "$(jq -nc --arg c "On it!" --arg m "$MESSAGE_ID" \
'{content: $c, message_reference: {message_id: $m}}')"sh
CHANNEL_ID="123456789012345678"; MESSAGE_ID="987654321098765432"
curl -sS -X POST \
-H "Authorization: Bot $DISCORDBOT_TOKEN" \
-H "Content-Type: application/json" \
"https://discord.com/api/v10/channels/$CHANNEL_ID/messages" \
-d "$(jq -nc --arg c "On it!" --arg m "$MESSAGE_ID" \
'{content: $c, message_reference: {message_id: $m}}')"Notes
注意事项
- A "server" in the UI is a "guild" in the API; messages live in channels inside guilds. Always: list guilds → list that guild's channels → act on a channel id. Don't invent ids.
- The bot only sees servers it was invited to. To add it: Developer Portal →
OAuth2 → URL Generator → scope + the permissions you need → open the URL → pick a server (the user needs Manage Server there).
bot - This is a bot, not the user's account — it cannot read the user's DMs or the user's full server list, only what the bot itself can access.
- Mentions: pings a user,
<@USER_ID>links a channel. Plain text is fine for normal messages.<#CHANNEL_ID>
- UI中的“server”对应API中的“guild”;消息存储在guild内的频道中。操作流程应为:列出guilds→列出该guild的频道→通过频道ID执行操作。请勿自行编造ID。
- Bot仅能查看已受邀加入的服务器。添加Bot的步骤:开发者门户→OAuth2→URL生成器→选择权限范围+所需权限→打开生成的URL→选择服务器(用户需拥有该服务器的管理服务器权限)。
bot - 这是Bot账号,而非用户个人账号——它无法读取用户的私信或用户的完整服务器列表,仅能访问Bot自身有权限的内容。
- 提及格式:用于@用户,
<@USER_ID>用于链接频道。普通消息使用纯文本即可。<#CHANNEL_ID>