You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Discord API发送消息时Embeds无法加载的解决咨询

问题

我正在编写一个重复@他人的脚本,尝试添加Embed时无法生效。使用superagent调用Discord API v9的代码如下:

const superagent = require("superagent");
const { log } = require('console');

// setInterval(() => {
    superagent.post("https://discord.com/api/v9/channels/person's user id/messages")
        .send({
            "content": "Asparagus",
            "flags": 0,
            "tts": false,
            "embeds": [
                {
                    "title": "Dontavious, spargus",
                    "type": "rich",
                    "description": "Spongebob, Asparagus Spongebob\nhttps://raw.githubusercontent.com/the-one-with-raspberry/random-file-bucket/main/spargus.jpeg\nhttps://media.tenor.com/images/3b0e2a9e7fe3f5d70de933b4057c3b0e/tenor.gif",
                    "color": 16711680,
                    "author": {
                        "name": "Dontavious",
                        "url": "https://raw.githubusercontent.com/the-one-with-raspberry/random-file-bucket/main/donta.jpg",
                        "icon_url": "https://raw.githubusercontent.com/the-one-with-raspberry/random-file-bucket/main/donta.jpg"
                    }
                }
            ]
        })
        .set('Authorization', "don't steal my token!!")
        .set('Content-Type', 'application/json')
        .end((err, res) => { if (err) throw err; log(`${res.body.embeds}`) })
// }, 2500)

运行后res.body.embeds返回空值,Discord中仅显示content内容,Embed未出现,请问该如何解决?

解决方法
  • 修正API端点路径:你当前请求URL中的channels/person's user id/messages是错误的,Discord发送消息的端点要求路径里是频道ID而非用户ID。将路径中的用户ID替换为目标频道的ID,这是导致Embed不显示的核心原因。
  • 校验Embed格式合规性:
    • author.url字段应指向可访问的网页链接,而非图片链接,虽然这不会直接导致Embed失效,但不符合Discord的规范;
    • 确保color值为有效的十进制RGB数值,你当前使用的16711680(红色)是合法的;
    • 确认描述中的图片链接可正常访问,失效链接会导致Embed加载异常。
  • 检查账号权限:确保发起请求的账号(Bot或用户)在目标频道拥有发送消息和嵌入链接的权限,权限不足时Discord会仅显示content内容,忽略Embed。
  • 打印详细错误信息:修改代码中的回调逻辑,输出完整的错误响应,以便定位问题:
    .end((err, res) => {
      if (err) {
        console.error(err.response?.body || err);
        return;
      }
      console.log(res.body);
    })
    
  • 确认Token有效性与权限范围:
    • 如果使用用户Token,确保账号未被Discord限制;
    • 如果使用Bot Token,需在OAuth2授权时勾选bot和必要的权限(如发送消息、嵌入链接),且Bot已加入目标服务器。

内容的提问来源于stack exchange,提问作者berriz44

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 20:04:59