node.js – discord.js v13 What code would I use to collect the first attachment (image or video) from a MessageCollector?

I’ve looked everywhere and tried all I could think of but found nothing, everything seemed to fail.

One bit of code I’ve used before that failed:

                Message.author.send({ embeds: [AttachmentEmbed] }).then(Msg => {
                    var Collector = Msg.channel.createMessageCollector({ MessageFilter, max: 1, time: 300000 });
                    Collector.on(`collect`, Collected => {
                        if (Collected.content.toLowerCase() !== `cancel`) {
                            console.log([Collected.attachments.values()].length);
                            if ([Collected.attachments.values()].length > 0) {
                                var Attachment = [Collected.attachments.values()];
                                var AttachmentType = `Image`;
                                PostApproval(false, Mode, Title, Description, Pricing, Contact, Attachment[0], AttachmentType);
                            } else if (Collected.content.startsWith(`https://` || `http://`) && !Collected.content.startsWith(`https://cdn.discordapp.com/attachments/`)) {
                                var Attachment = Collected.content.split(/[ ]+/)[0];
                                var AttachmentType = `Link`;
                                PostApproval(false, Mode, Title, Description, Pricing, Contact, Attachment, AttachmentType);
                                console.log(Attachment)
                            } else if (Collected.content.startsWith(`https://cdn.discordapp.com/attachments/`)) {
                                var Attachment = Collected.content.split(/[ ]+/)[0];
                                var AttachmentType = `ImageLink`;
                                PostApproval(false, Mode, Title, Description, Pricing, Contact, Attachment, AttachmentType);
                                console.log(Attachment)
                            }

Read more here: Source link