Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

604
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda