1
0
Fork 0
Spiegel von https://github.com/aydenjahola/discord-multipurpose-bot.git synchronisiert 2025-07-05 19:56:24 +01:00

trivia: add option for a random trivia

Dieser Commit ist enthalten in:
Ayden Jahola 2024-09-24 12:25:21 +01:00
Ursprung 2e9d53ffc5
Commit 7376649895
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 71DD90AE4AE92742

Datei anzeigen

@ -276,9 +276,10 @@ module.exports = {
.addStringOption((option) =>
option
.setName("category")
.setDescription("Choose a trivia category")
.setDescription("Choose a trivia category or random")
.setRequired(true)
.addChoices(
{ name: "Random", value: "random" },
...Object.entries(CATEGORY_MAP).map(([value, name]) => ({
name,
value,
@ -303,8 +304,19 @@ module.exports = {
ACTIVE_GAMES.add(userId);
try {
const categoryId = interaction.options.getString("category");
const categoryName = CATEGORY_MAP[categoryId] || "Video Games";
let categoryId = interaction.options.getString("category");
let categoryName;
if (categoryId === "random") {
// Choose a random category from CATEGORY_MAP
const categoryKeys = Object.keys(CATEGORY_MAP);
const randomKey =
categoryKeys[Math.floor(Math.random() * categoryKeys.length)];
categoryId = randomKey; // This is now valid
categoryName = CATEGORY_MAP[randomKey];
} else {
categoryName = CATEGORY_MAP[categoryId] || "Video Games";
}
const { triviaQuestion, source } = await fetchTriviaQuestion(
userId,