R0CK3T_DEV
R0CK3T_DEV

Reputation: 25

How can I re-send an attachment from a message?

So, what I want to do is something like this:

User: sends a command like this: mybot!announce @mention (message) (Attachs image)

Bot: gets the mention, message & attachment from the message, and deletes it. Then resends the message in an embed (see picture).

I managed to do everything else but I can't get the attachment & re-send it in the embed. Please, help :p Here is what the bot actually does.

Here is the code I actually have, in case you need it:


if (command === 'announce')
      {
        
        var mention = args[0];

        if (!args[0]) return message.channel.send('You need to mention someone!');

        var actualMention = null;

        if (mention === '@everyone')
        {
            actualMention = message.mentions.members.every();
        }
        else
        {
            actualMention = message.mentions.members.first();
        }

        var messageAnnouncement = args.slice(1).join(" ");

        if (msgAnnouncement === null) return message.channel.send('You need to put the announcement itself!');

        var imageAttachments = message.attachments;

        const anunouncementEmbed = new Discord.MessageEmbed()
        .setAuthor('YPBot - Announcement')
        .setTitle(message.author.tag + ' made an announcement')
        .setDescription('Mentioning: ' + mention + '\n\n' + 
        msgAnnouncement)
        .setThumbnail(imageAttachments[0]);

        message.channel.send(anunouncementEmbed);

      }

Hope I explained myself well. In case I didn't, feel free to ask anything.

Upvotes: 0

Views: 458

Answers (1)

Lioness100
Lioness100

Reputation: 8412

Message#attachments actually returns a Collection, so if you want the first element you need Collection#first(). From there you can access the MessageAttachment#url property.

.setThumbnail(imageAttachments.first().url);

Upvotes: 1

Related Questions