'discord bot is not sending image of collected URL while using collector

I am trying to do a simply paste a link in a particular channel and wait for the bot to send it again with message.

here in this example I should get:

hello image

but I am only getting hello and I even tried some different methods like changing

message.channel.send(`hello,${m.content}`)

the output comes with the URL and image, but I don't need the URL I only need the image and the text.

here is my part of the code.

const collector = message.channel.createMessageCollector({
    filter,
    max : 1 , 
    time: 15000});

collector.on('collect', m => {
                                console.log(`Collected ${m.content}`);
                            });
collector.on('end', collected => {
    console.log(`Collected ${collected.size} items`);
    message.channel.send("hello",{files: collected.map(msg => msg.content)})

});


Solution 1:[1]

just needed to use MessageAttachment and you can send the image without link. reference

const { MessageAttachment } = require('discord.js')

//collector
const collector = message.channel.createMessageCollector({
    filter,
    max : 1 , 
    time: 15000});

collector.on('collect', m => {
const attachment = new MessageAttachment('https://i.imgur.com/XATplyx.jpeg')// your URL
message.channel.send({ content: "Hello", files: [attachment] })
                                console.log(`Collected ${m.content}`);
                     });

collector.on('end', collected => {
    console.log(`Collected ${collected.size} items`);
});

Solution 2:[2]

You're trying to send strings into files. That's not possible. If you wan't to see all collected messages, you can use;

message.channel.send(`Hello: ${collected.map(msg => msg.content).join(",")}`)

This's gonna work if i understood right what you want.

collected messages

This is how you get text and i saw your image request after i post. Here's how you get image of collected message if url is in the message the collected.content will send photo again don't need to do something else but if someone posts photo from gallery by pressing upload button then you need to;

collector.on("end", async collected => 
{
let attachments = []
collected.forEach(msg => attachments.push(msg.attachments.first().url))
await message.channel.send({content: "Hello", files: attachments})

})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 noobuZter69
Solution 2