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!