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

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:
image.png
Was this page helpful?