0
votes

I'm trying to collect attachments from a message and then send them in an embed. I've tried this:

attachment = message.attachments.first()
url = attachment.url

const embedmem = new Discord.MessageEmbed()
    .setColor('#ffffff')
    .setTitle('Title')
    .setDescription('Description')
    .setImage(url)
message.channel.send(embedmem);

But no images appeared. Please tell me if I'm doing something wrong.

1

1 Answers

1
votes

You should define your variables (such as attachment and URL) using const/let/var etc... (depending on your needs).

const Attachment = message.attachments.first(); // Getting the attachment.

const Embed = new Discord.MessageEmbed() // Creating an embed message.
    .setColor("#ffffff")
    .setTitle("Title")
    .setDescription("Description")
    if (Attachment && Attachment.url) {Embed.setImage(Attachment.url)} // If the attachment exists we are adding the image.
message.channel.send(Embed);