I'm doing a quizz with some questions:
const questions = [
{
question: "What is the capital of France?",
answer: "Paris",
},
{
question: "Who is the best barcelona player of all history?",
answer: "Messi",
},
];
What works: When the user have the correct answer, the next question is show up and when all the questions are displayed, the quizz is finish
What is the problem: The user have 10 seconds for give a answer. So if nobody have the correct answer in 10 answer, the next question is displayed.So currently, nothing happened in 10 seconds and it's block to the same question.
This is my script:
client.on('messageCreate', async message => {
//...
const handleQuestion = () => {
if (i >= questions.length) {
return;
}
channel.send(questions[i].question);
// Create a collector to get the answers from users
const filter = m => !m.author.bot;
const collector = channel.createMessageCollector(filter, { time: 10000 });
collector.on('collect', message => {
if (message.content === questions[i].answer) {
channel.send(`${message.author} a trouvé la bonne réponse!`);
collector.stop();
}
});
collector.on('end', collected => {
i++;
if (i >= questions.length) {
channel.send('Toutes les questions ont été posées!');
return;
}
if (!collected.size) {
channel.send(`Aucune réponse n'a été trouvée pour la question "${questions[i].question}"`);
}
handleQuestion();
});
};
handleQuestion();
}
});
client.login('Token_discord');
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2qp0xyK
Comments
Post a Comment