I'm trying to add a URL shortener to my discord bot. So far, I've found this npm package. I've applied it to my code here:
async execute(interaction) {
let longURL = interaction.options.getString("url");
var shortenedURL;
isgd.shorten(longURL, function (url) {
shortenedURL = url;
console.log(shortenedURL);
});
const embed = new MessageEmbed()
.setColor("#0099ff")
.setTitle("๐ Shortened URL")
.setDescription(`${shortenedURL}`);
if (!longURL) {
await interaction.reply({
embeds: [embed.setDescription("Please enter a valid URL to shorten")],
ephemeral: true,
});
} else {
await interaction.reply({
embeds: [embed.setDescription(`${shortenedURL}`)],
});
}
}
When I console.log(shortenedURL) within isgd.shorten, I receive a value. Yet I always get undefined when the message appears on the server. Why is it not properly passing the value I get to the message?