Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda