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

600
Visualizações
Discord.js v13 - Extract Image Embed attached in Message

I am writing a function that returns an Image Embed from a Message. I mean, Image from MessageEmbed.

The thing: Discord resolves the Image URL and returns an Image Embed object instead (can be found using message.embeds property).

Here's an example image

And here is the main problem:

When you are trying to access in embeds property from Message Object, will get an empty Array like this: []. But accessing again will get the expected result. [ [MessageEmbed] ] An ImageEmbed.

The problem with this is Discord takes some time to resolve the URL and displays into Message as Attachment, and dont want to use the setTimeout function to wait it. Because if the message contains multiple image URLs this will take more time. Well... trying to access in embeds property after that operation will not work properly because returns again... an empty array.

So looking the messageUpdate event i found that emits the same Message with the Image URL resolved in embeds property. So i make this code:

async function getImageEmbeds(message) {
   // Access into Client to listen the messageUpdate event.
   const { client } = message;
   const collectedImages = new Array();

   // Waits the event emittion
   await new Promise((resolve) => {
      function fnListener(oldmsg, newmsg) {
         if (message.id !== newmsg.id) return;
         const imageEmbeds = newmsg.embeds.filter(embed => embed.thumbnail !== null).map(embed => embed.thumbnail);
         collectedImages.push(...imageEmbeds);
       
         client.removeListener("messageUpdate", fnListener);
         // Ends this promise.
         resolve(true);
      }
      client.on("messageUpdate", fnListener);
   })

   return collectedImages;
}

This code works as expected (Waits the Image URL resolving that will be emitted in messageUpdate event and returns an Array with the Image Embed resolved). But there's a new problem, The function will wait indefinitely if the message doesn't have an Image URL.

  • How i can tell to the function if the message has an unresolved Image URL?

Any suggestions that can solve this problem?

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