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

如何让自定义Discord Bot返回含超链接的Embed消息?

解决Discord Bot /betslip命令的动态链接问题

你的代码里有两个关键问题导致链接显示为null:

  • 获取用户输入的选项时,getString的参数应该是字符串'link',而非未定义的变量link
  • setDescription方法不需要传递对象,直接传入描述字符串即可

修正后的完整代码如下:

const { SlashCommandBuilder, EmbedBuilder, hyperlink } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('betslip')
        .setDescription('this will send an embed with a link to your betslip')
        .addStringOption(option =>
            option.setName('link')
                .setDescription('Your betslip link')
                .setRequired(true)
                .setMaxLength(2000)),
    async execute(interaction) {
        // 修正:用字符串'link'作为参数获取用户输入的链接
        const link = interaction.options.getString('link');

        const embed = new EmbedBuilder()
            .setColor('Aqua')
            .setTitle(`Please ${hyperlink('click here', link)} to place this bet on FanDuel.`)
            // 修正:直接传入描述字符串
            .setDescription(`Always check selections and odds before placing wager. Gamble responsibly.`)
            .setTimestamp()
        
        await interaction.reply({embeds: [embed]});
    }
}

修正后,用户执行/betslip并提供链接时,Embed消息里的超链接会正确指向用户输入的地址,不再出现null的情况。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 12:17:06