fix a bug where if the user enocouters an error it would still wouild be makred as ongoing trivia

This commit is contained in:
Ayden Jahola 2024-09-06 00:00:30 +01:00
parent 50bfb9c6e3
commit d693d2f714
No known key found for this signature in database
GPG key ID: 71DD90AE4AE92742

View file

@ -43,8 +43,10 @@ module.exports = {
// Add the user to the set of active trivia players // Add the user to the set of active trivia players
ongoingTrivia.add(userId); ongoingTrivia.add(userId);
try {
const categoryId = interaction.options.getString("category"); const categoryId = interaction.options.getString("category");
const categoryName = categoryId === "15" ? "Video Games" : "Anime & Manga"; const categoryName =
categoryId === "15" ? "Video Games" : "Anime & Manga";
// Fetch a trivia question from the cache or the API // Fetch a trivia question from the cache or the API
let triviaQuestion = await TriviaQuestion.findOne({ let triviaQuestion = await TriviaQuestion.findOne({
@ -190,5 +192,18 @@ module.exports = {
ongoingTrivia.delete(userId); ongoingTrivia.delete(userId);
} }
}); });
} catch (error) {
console.error("Error fetching trivia question:", error);
// Inform the user about the error and let them retry
await interaction.reply({
content:
"There was an error fetching your trivia question. Please try again later.",
ephemeral: true,
});
// Remove the user from the ongoing trivia set in case of an error
ongoingTrivia.delete(userId);
}
}, },
}; };