Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Why does this var not get passed after recieving a new value?

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?

about 4 years ago ยท Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!