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

192
Visualizações
User image to Discord Embed

I want the image that a user sends to be fetched and put into an embed that the bot will then send. As the image must be a url and the person sends an image, I don't know how I can transform this image into a url. When doing the command, the embed send but without the image. This is what i've tried but it didn't work :

const plotEmbed = new Discord.MessageEmbed() 
                        .setTitle(`Purchase of the plot n°${plotId}`)
                        .setColor("GREEN")
                        .setDescription(`Purchase of plot ${plotId} for ${days} days.`)
                        .setImage(message.attachments.first.url)
                        .setTimestamp()
message.channel.send({ embeds: [pEmbed]})

If someone could get me an advice on what I should try because I don't really know... Thanks for reading.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Using message.attachments gives a collection, so you can use the .map() command to get the urls. All you have to do is change your code to:

const attachmentURL = message.attachments.map(attachment => attachment.url)
const plotEmbed = new Discord.MessageEmbed()
  .setTitle(`Purchase of the plot n°${plotId}`)
  .setColor("GREEN")
  .setDescription(`Purchase of plot ${plotId} for ${days} days.`)
  .setImage(attachmentURL[0])
  .setTimestamp()
message.channel.send({
  embeds: [pEmbed]
})

This might just be the fact that pEmbed was declared before your code snippet but just wanted to tell that you are sending an embed called pEmbed while the embed in your current code snippet is in a variable called plotEmbed, so you might want to change that.

Edit:

Just found another way which is the simpler one. You just made a mistake calling message.attachments.first. It should actually be message.attachments.first().url because first() is actually a function. So this should also work exactly like the first method I posted

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