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

如何为Discord Embed消息添加带跳转链接的交互式按钮?

给Discord Embed添加跳转链接按钮的实现方法

要给你的Embed消息加上跳转链接按钮,需要用到discord.js里的MessageActionRow和MessageButton组件,以下是修改后的完整代码:

const Discord = require("discord.js")
const { Client, Message, MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');

module.exports = {
    name: 'text',
    cooldown: 1000,
    run: async(client, message, args) => {
        message.delete()
        const exampleEmbed = new MessageEmbed()
            .setColor('#000')
            .setAuthor("Text")
            .setDescription('Text')
            .addFields(
                {
                    name: `TextTitle`,
                    value: `Text`,
                    inline: true
                },
                {
                    name: `TextTitle`,
                    value: `Text`
                }       
            )

        // 创建跳转按钮
        const linkButton = new MessageButton()
            .setLabel('点击跳转') // 按钮上显示的文字
            .setURL('https://你的目标链接地址.com') // 替换成你需要跳转的实际链接
            .setStyle('LINK'); // 链接按钮必须使用LINK样式

        // 将按钮放入消息行组件
        const actionRow = new MessageActionRow().addComponents(linkButton);

        // 同时发送Embed和按钮组件
        message.channel.send({ embeds: [exampleEmbed], components: [actionRow] })
    }
}

关键说明:

  • 必须导入MessageActionRow和MessageButton组件,否则无法创建按钮
  • 跳转按钮的样式必须设为LINK,这是Discord专门用于外部跳转的按钮类型,点击后直接打开链接,不需要额外处理交互事件
  • 发送消息时要改用对象格式,通过embeds数组传入Embed,components数组传入按钮行

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 17:55:29