Memeloren
Memeloren

Reputation: 29

Discord.JS getting all attachments from a message

Hi I'm tying to make a say command that sends attachments that was sent while using the command for example someone uses !say while attaching 3 attachment and it sends the 3 attachments last time I tried to do it I could only get the first attachment but I want to get all the attachments that was attached with the message

Upvotes: 0

Views: 4549

Answers (1)

SirArchibald
SirArchibald

Reputation: 516

If you want to get the files or images that are attached to a message, you can access the attachments property of the message object. This will return a Collection of attachments that you can iterate through and attach to your new message.

e.g.

client.on("message", message => {
    if (message.attachments) {
        let attachments = message.attachments;
        for (let file of attachments) {
            message.channel.send({files: [file]});
        }
    }
})

You can get more information about this in the Discord.js documentation.

Upvotes: 2

Related Questions