mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-15 00:12:38 +02:00
Quiz type choice
This commit is contained in:
+19
-4
@@ -11,19 +11,34 @@ module.exports = class QuizCommand extends Command {
|
||||
group: 'games',
|
||||
memberName: 'quiz',
|
||||
description: 'Answer a true/false quiz question.',
|
||||
clientPermissions: ['EMBED_LINKS']
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'type',
|
||||
prompt: 'Which type of question would you like to have? `multiple` or `boolean`.',
|
||||
type: 'string',
|
||||
default: 'boolean',
|
||||
validate: type => {
|
||||
if (['multiple', 'boolean'].includes(type.toLowerCase())) return true;
|
||||
return 'Please enter either `multiple` or `boolean`.';
|
||||
},
|
||||
parse: type => type.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
async run(msg, args) {
|
||||
const { type } = args;
|
||||
const { body } = await snekfetch
|
||||
.get('https://opentdb.com/api.php')
|
||||
.query({
|
||||
amount: 1,
|
||||
type: 'boolean',
|
||||
type,
|
||||
encode: 'url3986'
|
||||
});
|
||||
const answer = body.results[0].correct_answer.toLowerCase();
|
||||
if (!body.results.length) return msg.say('Oh no, a question could not be fetched. Try again later!');
|
||||
const answer = decodeURIComponent(body.results[0].correct_answer.toLowerCase());
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle('You have 15 seconds to answer this question:')
|
||||
.setDescription(stripIndents`
|
||||
|
||||
Reference in New Issue
Block a user