mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 08:45:55 +00:00
trivia: reset user's steak when time is up
This commit is contained in:
parent
9d3a56a640
commit
616d823dde
1 changed files with 20 additions and 4 deletions
|
@ -191,11 +191,27 @@ const handleAnswerCollection = async (
|
|||
}
|
||||
});
|
||||
|
||||
answerCollector.on("end", (collected, reason) => {
|
||||
answerCollector.on("end", async (collected, reason) => {
|
||||
if (reason === "time") {
|
||||
interaction.followUp(
|
||||
`<@${userId}> Time's up! the correct answer is **${correctAnswer}.**`
|
||||
// Reset the user's streak when time runs out
|
||||
try {
|
||||
let userScore = await Leaderboard.findOne({ userId });
|
||||
if (userScore) {
|
||||
userScore.streak = 0; // Reset streak
|
||||
await userScore.save();
|
||||
}
|
||||
|
||||
await interaction.followUp(
|
||||
`<@${userId}> Time's up! The correct answer is **${correctAnswer}**. Your current streak is **${userScore.streak}**.`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error resetting streak after time limit:", error);
|
||||
await interaction.followUp({
|
||||
content: "There was an error resetting your streak.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
ONGOING_TRIVIA.delete(userId);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue