Message Collector From Chat

client.on('messageCreate', async message => {
let args = message.content.split(" ");
if (args[0] === `event`) {
if (message.author.id !== "222534954196664320") return;
await message.delete().catch(err => { console.log(err) });
let channel = client.channels.cache.get(Ch);
let MainCh = client.channels.cache.get(Main);
let uploaded = false;
await channel.messages.fetch().then(msgs => {
for (const msg of msgs) {
if (msg[1].attachments.size > 0) {
const collector = MainCh.createMessageCollector({ time: 10000 });
collector.on('collect', async m => {
if (m.content === msg[1].content) {
await m.reply(`Correct!`).catch(err => { console.log(err) });
uploaded = true;
collector.stop();
}
})
collector.on('end', async () => {
if (!uploaded) {
MainCh.send(`The time is done, and no one choose the correct answer.`).catch(err => { console.log(err) });
}
})
}
}
}).catch(err => { console.log(err) });
}
})
client.on('messageCreate', async message => {
let args = message.content.split(" ");
if (args[0] === `event`) {
if (message.author.id !== "222534954196664320") return;
await message.delete().catch(err => { console.log(err) });
let channel = client.channels.cache.get(Ch);
let MainCh = client.channels.cache.get(Main);
let uploaded = false;
await channel.messages.fetch().then(msgs => {
for (const msg of msgs) {
if (msg[1].attachments.size > 0) {
const collector = MainCh.createMessageCollector({ time: 10000 });
collector.on('collect', async m => {
if (m.content === msg[1].content) {
await m.reply(`Correct!`).catch(err => { console.log(err) });
uploaded = true;
collector.stop();
}
})
collector.on('end', async () => {
if (!uploaded) {
MainCh.send(`The time is done, and no one choose the correct answer.`).catch(err => { console.log(err) });
}
})
}
}
}).catch(err => { console.log(err) });
}
})
I'm using an attachments and message content (made the bot to get it from private chat), to get the question and answer like this:
No description
9 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Forhand.
Forhand.OP15mo ago
and I'm using this method because I made a lot of users able to apply their own question and answer.
Amgelo
Amgelo15mo ago
you are creating a collector for every message on the channel? what do you want to do?
Forhand.
Forhand.OP15mo ago
yes to get the right answer within 10 seconds
Amgelo
Amgelo15mo ago
I don't quite get what you're trying to do
Forhand.
Forhand.OP15mo ago
The bot will take the attachment from chat1 and send it in chat2 then there's gonna be a collector in chat2 to get the correct answer (which will be the attachment's message content) within 10 seconds or the collector will stop, after that it's gonna take the second attachment in chat1 and so on until he sends all the attachments in the chat1 that's it
Amgelo
Amgelo15mo ago
so you actually only need one collector, and the next is created after the last question in the queue "expires" assuming there's a next one in the queue
Forhand.
Forhand.OP15mo ago
exactly
Amgelo
Amgelo15mo ago
well that's not really what your code is doing your code is directly creating every collector at once so they all expire at pretty much the same time
Want results from more Discord servers?
Add your server