Discord bot embed with dynamic hyperlink - How to include user-provided URL in embedded message?

I’m pretty new to JavaScript and working on a Discord bot. I want to create a slash command called /wager that takes a URL from the user and returns an embed message with that link clickable inside it.

What I’m trying to do:

  • User types: /wager [their link]
  • Bot responds: Embed saying “Click this link [user’s URL] to submit your wager on DraftKings”

I got a basic embed working with a hardcoded link, but I can’t figure out how to make it use the link that the user provides. Right now my code gives me a null value instead of the actual URL.

Here’s my current code:

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

module.exports = {
    data: new SlashCommandBuilder()
        .setName('wager')
        .setDescription('creates embed with your wager link')
        .addStringOption(option =>
            option.setName('url')
                .setDescription('Your wager URL')
                .setRequired(true)
                .setMaxLength(2000)),
    async execute(interaction) {
        const url = interaction.options.getString(url);
        
        const embedMessage = new EmbedBuilder()
            .setColor('Blue')
            .setTitle(`Please ${hyperlink('click this link', url)} to submit your wager on DraftKings.`)
            .setDescription({text: `Double check your picks and odds first. Bet responsibly.`})
            .setTimestamp()
        
        await interaction.reply({embeds: [embedMessage]});
    }
}

What I’m getting: Please [click this link](null) to submit your wager on DraftKings.

Any help would be awesome. Thanks!

Both answers above got the syntax right, but here’s another tip. When your Discord bot handles user URLs, add basic validation first - check if it’s actually a valid URL before making the embed. I learned this when users kept sending random text instead of URLs and my bot made broken embeds. Just add if (!url.startsWith('http://') && !url.startsWith('https://')) before creating your embed, then send an error message if it fails. Saves you from broken hyperlinks and makes the bot way more user-friendly. Discord.js hyperlink function doesn’t validate URLs automatically, so bad links will still create embeds but won’t be clickable.

hey! found ur problem - ur missing quotes around ‘url’ in your getString call. it should be interaction.options.getString('url') not interaction.options.getString(url). that’s why ur getting null instead of the actual URL value.

Yeah, Claire29 nailed it - you need quotes around the parameter name. But there’s another issue: setDescription expects a string, not an object. Change .setDescription({text: 'Double check your picks and odds first. Bet responsibly.'}) to .setDescription('Double check your picks and odds first. Bet responsibly.'). I ran into this same problem when I started with Discord.js embeds. Took me forever to realize setDescription doesn’t work like other methods that take objects. Fix both the getString parameter and description format and you’ll be good to go.