added mognodb database
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const quiz = require('./quiz.json');
|
||||
const {SlashCommandBuilder} = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("quiz")
|
||||
.setDescription("Start a cool quiz"),
|
||||
async execute(interaction) {
|
||||
const item = quiz[Math.floor(Math.random() * quiz.length)];
|
||||
await interaction.reply({
|
||||
content: `**Quiz Time!**\n${item.question}\n\n_You have 30 seconds to answer!_`,
|
||||
});
|
||||
|
||||
// Define a filter to check the correct answer
|
||||
const collectorFilter = (response) => {
|
||||
return (
|
||||
response.author.id === interaction.user.id && // Ensure it's the same user
|
||||
item.answers.some(
|
||||
(answer) => answer.toLowerCase() === response.content.toLowerCase()
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
try {
|
||||
// Await messages in the same channel
|
||||
const collected = await interaction.channel.awaitMessages({
|
||||
filter: collectorFilter,
|
||||
max: 1,
|
||||
time: 30000, // 30 seconds
|
||||
errors: ['time'],
|
||||
});
|
||||
|
||||
// If a message is collected, reply with the correct response
|
||||
const correctAnswer = collected.first();
|
||||
await interaction.followUp(
|
||||
`${correctAnswer.author} got the correct answer: **${correctAnswer.content}**! 🎉`
|
||||
);
|
||||
} catch (err) {
|
||||
// If no one answers in time
|
||||
await interaction.followUp(
|
||||
`⏳ Time's up! Nobody got the correct answer. The correct answers were: **${item.answers.join(', ')}**.`
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
[
|
||||
{
|
||||
"question": "What color is the sky?",
|
||||
"answers": ["blue"]
|
||||
},
|
||||
{
|
||||
"question": "How many letters are there in the alphabet?",
|
||||
"answers": ["26", "twenty-six", "twenty six", "twentysix"]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user