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

Discord embed系统完整文档查询及嵌入按钮添加开发求助

核心误区

按钮、下拉菜单等交互组件不属于Embed对象的内置属性,不存在“给Embed对象加按钮”的配置方式。交互组件是和Embed平级的独立消息结构,挂载在消息体的components字段下,而非嵌套在Embed内部,这也是你翻遍Embed属性说明都找不到按钮相关配置的核心原因。

原生Embed对象全属性说明

Discord原生Embed对象支持的所有配置项如下:

  • 顶层通用属性
    • title:字符串类型,Embed标题,最大长度256字符
    • description:字符串类型,Embed正文内容,最大长度4096字符,支持Discord Markdown语法
    • color:整数类型,对应Embed左侧边栏的显示颜色,支持直接传十进制色值或十六进制色值转十进制
    • timestamp:ISO8601标准格式时间戳,传入后会在Embed底部显示对应时间
    • url:字符串类型,传入后title字段会自动变为可跳转的超链接
    • author:对象类型,对应Embed顶部作者栏,支持3个子属性:name(作者名称,最大长度256字符)、url(作者名跳转链接)、icon_url(作者头像图片地址)
    • thumbnail:对象类型,对应Embed右上角缩略图,仅需传入url字段指定图片地址
    • image:对象类型,对应Embed正文下方的大图,仅需传入url字段指定图片地址
    • footer:对象类型,对应Embed底部脚注栏,支持2个子属性:text(脚注文本,最大长度2048字符)、icon_url(脚注图标图片地址)
    • fields:对象数组类型,对应Embed的字段列表,最多支持传入25个字段,每个字段支持3个属性:name(字段标题,最大长度256字符)、value(字段内容,最大长度1024字符,支持Discord Markdown语法)、inline(布尔值,设置为true时字段将横向并排显示)

约束规则:单个Embed所有文本内容累计长度不能超过6000字符,单条消息最多可同时携带10个Embed。

带按钮的Embed消息原生写法

你已经编写完成的Embed模板不需要做任何修改,只需要在构造消息发送体时,和embeds数组平级添加components字段存放按钮即可,参考示例:

// 你原有的Embed对象保持不变
const embed = {
    "title": "Hello ~~people~~ world :wave:",
    "description": "You can use [links](https://discord.com) or emojis :smile: 😎\n```\nAnd also code blocks\n```",
    "color": 4321431,
    "timestamp": "2022-07-03T18:07:18.372Z",
    "url": "https://discord.com",
    "author": {
        "name": "Author name",
        "url": "https://discord.com",
        "icon_url": "https://unsplash.it/100"
    },
    "thumbnail": {
        "url": "https://unsplash.it/200"
    },
    "image": {
        "url": "https://unsplash.it/380/200"
    },
    "footer": {
        "text": "Footer text",
        "icon_url": "https://unsplash.it/100"
    },
    "fields": [
        {
            "name": "Field 1, *lorem* **ipsum**, ~~dolor~~",
            "value": "Field value"
        },
        {
            "name": "Field 2",
            "value": "You can use custom emojis <:Kekwlaugh:722088222766923847>. <:GangstaBlob:742256196295065661>",
            "inline": false
        },
        {
            "name": "Inline field",
            "value": "Fields can be inline",
            "inline": true
        },
        {
            "name": "Inline field",
            "value": "*Lorem ipsum*",
            "inline": true
        },
        {
            "name": "Inline field",
            "value": "value",
            "inline": true
        },
        {
            "name": "Another field",
            "value": "> Nope, didn't forget about this",
            "inline": false
        }
    ]
}

// 消息发送完整结构
const messagePayload = {
    embeds: [embed], // 传入需要发送的Embed数组
    components: [ // components和embeds平级,存放所有交互组件
        {
            type: 1, // 固定值1代表ActionRow,即一行组件容器
            components: [
                {
                    type: 2, // 固定值2代表按钮组件
                    style: 1, // 按钮样式:1主色、2次色、3成功、4危险、5链接
                    label: "测试按钮",
                    custom_id: "test_button_001", // 非链接按钮必填,用于接收交互回调
                    emoji: { name: "👋" } // 可选,为按钮添加emoji
                },
                {
                    type: 2,
                    style: 5,
                    label: "跳转链接",
                    url: "https://discord.com" // 链接按钮必填,替换custom_id字段
                }
            ]
        }
    ]
}

组件使用注意事项:

  • 每个ActionRow(type: 1的组件容器)最多放置5个按钮,单条消息最多支持5个ActionRow
  • 所有交互组件(按钮、下拉选择菜单、文本输入框等)都必须放在ActionRow容器内,不能直接挂在components数组下
  • 非链接类型按钮(样式值为1/2/3/4)必须设置全局唯一的custom_id字段,用户点击按钮时Discord会将该ID推送至你的服务端,用于识别交互来源

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 06:03:12