0

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)})

});

2 Answers 2

0

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})

})
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your input @Neenhila but its giving me this output error: TypeError: collected.foreach is not a function.
the first part seems good but I actually needed the second part which is having error.
Did you try to write forEach? Or just wrote foreach?
Also you need to check if there's no collected message then there can't be forEach of nothing. Check whether if it has 1 or more and then do codes below.
none of the above seems to be the problem code
0

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`);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.