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

364
Vistas
image url showing as undefined discord.js

so I'm making a discord bot as a small project and when I try to get the url from an image attachment it shows up as undefined. here's my code:

var attachment = message.attachments
if (message.content.includes("is dropping 3 cards!")) {
    let image = attachment
    console.log(image.url)
}

when I use this code the image url shows up as undefined and I don't know why. I've tried using image without .url and the url seems to show up but when I use .url it doesn't seem to work.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Now now, message.attachments contains an array. The attachment can be image, video or file. There can be also multiple attachments in one message. Meaning that you need to define which one of the attachments you want to use. You should also check if there is any attachments in the message before going forward.

Below is little example for using the first file/image in the message:

if(message.attachments.size > 0) {
     var attachment = message.attachments.first();
     console.log(attachment.url)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try console logging just attachment and seeing if that gives you any results. It should return an array of attachments which you would either need to map through or set an index value to your attachment ie. attachment[0].url. Also, there's no need for declare the image variable as its not saving you any time. attachment.url is the same thing as image.url and it just makes things more confusing than it needs to be.

about 4 years ago · Juan Pablo Isaza Denunciar
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