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

如何在Discord.js v12.6机器人的嵌入消息中添加独立自定义链接

在Discord.js v12.6中添加独立的「立即申请」链接到嵌入消息

嘿,我完全懂你的需求——不想让嵌入消息的标题绑定申请链接,而是要一个独立的「立即申请」可点击标签对吧?咱们来搞定这个问题:

首先得明确,Discord.js里的setURL()方法本身就是专门给嵌入消息的标题设置跳转链接的,这就是为什么你会看到标题变成可点击状态。要实现独立的申请链接,咱们可以利用Discord支持在嵌入字段值里使用Markdown链接的特性,具体有两种常用实现方式:

方法1:新增独立的「立即申请」字段

直接添加一个单独的字段,把Markdown格式的链接放进去,这样就能得到一个完全独立的可点击申请入口:

const embed = new MessageEmbed()
 .setColor('#ffdf00')
 .setTitle(companyName)
 .addFields(
 { name: 'Position', value: jobTitle, inline:true },
 { name: 'Location', value: location, inline:true },
 { name: 'Experience', value: experienceLevel, inline: true },
 { name: 'Salary Range', value: CTCRange, inline: true },
 )
 .addFields({ name: 'Qualifications', value: qualificationRequired })
 // 新增独立的申请链接字段
 .addFields({ name: '申请通道', value: `[立即申请](${linktoApply})` })
// 一定要删掉原来的.setURL(linktoApply),避免标题被绑定链接

const channel = client.channels.cache.get(channelID);
channel.send(embed);

方法2:把链接附加到现有字段末尾

如果不想额外新增字段,也可以把申请链接加到某个现有字段的内容后面,比如资格要求字段的底部:

const embed = new MessageEmbed()
 .setColor('#ffdf00')
 .setTitle(companyName)
 .addFields(
 { name: 'Position', value: jobTitle, inline:true },
 { name: 'Location', value: location, inline:true },
 { name: 'Experience', value: experienceLevel, inline: true },
 { name: 'Salary Range', value: CTCRange, inline: true },
 )
// 在资格要求内容末尾添加申请链接
 .addFields({ name: 'Qualifications', value: `${qualificationRequired}\n\n[立即申请](${linktoApply})` })
// 同样要删除原来的.setURL(linktoApply)

const channel = client.channels.cache.get(channelID);
channel.send(embed);

小提示

  • 确保linktoApply是完整有效的URL(比如以https://开头),否则Discord不会将其渲染为可点击链接
  • 如果使用inline: true的字段,尽量避免在字段内添加过多换行,以免破坏排版美观

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 13:27:28