mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 08:45:55 +00:00
trivia: add option for a random trivia
This commit is contained in:
parent
2e9d53ffc5
commit
7376649895
1 changed files with 15 additions and 3 deletions
|
@ -276,9 +276,10 @@ module.exports = {
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("category")
|
.setName("category")
|
||||||
.setDescription("Choose a trivia category")
|
.setDescription("Choose a trivia category or random")
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
.addChoices(
|
.addChoices(
|
||||||
|
{ name: "Random", value: "random" },
|
||||||
...Object.entries(CATEGORY_MAP).map(([value, name]) => ({
|
...Object.entries(CATEGORY_MAP).map(([value, name]) => ({
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
|
@ -303,8 +304,19 @@ module.exports = {
|
||||||
ACTIVE_GAMES.add(userId);
|
ACTIVE_GAMES.add(userId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const categoryId = interaction.options.getString("category");
|
let categoryId = interaction.options.getString("category");
|
||||||
const categoryName = CATEGORY_MAP[categoryId] || "Video Games";
|
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(
|
const { triviaQuestion, source } = await fetchTriviaQuestion(
|
||||||
userId,
|
userId,
|
||||||
|
|
Loading…
Reference in a new issue