From aea45cff38e86c8f40b6ad1909e1ee3bf6898b13 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 23 Mar 2017 21:33:45 +0000 Subject: [PATCH] Let's Try This Crazy Stuff --- commands/random/quiz.js | 49 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/commands/random/quiz.js b/commands/random/quiz.js index 0b50fea5..5cbe6b4b 100644 --- a/commands/random/quiz.js +++ b/commands/random/quiz.js @@ -21,29 +21,30 @@ module.exports = class QuizCommand extends commando.Command { if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS'])) return; } console.log("[Command] " + message.content); - return request - .get('http://jservice.io/api/random') - .query({ - count: 1 - }) - .then(function(response) { - const embed = new Discord.RichEmbed() - .setTitle('You have **fifteen** seconds to answer this question:') - .setDescription(`**Category: ${response.body[0].category}**\n${response.body[0].question}`); - message.channel.sendEmbed(embed).then(() => { - message.channel.awaitMessages(res => res.content.toLowerCase() === response.body[0].answer.toLowerCase() && res.author.id === message.author.id, { - max: 1, - time: 15000, - errors: ['time'], - }).then((collected) => { - return message.channel.send(`Good Job! You won!`); - }).catch(() => { - return message.channel.send(`Aw... Too bad, try again next time!\nThe Correct Answer was: ${response.body[0].answer}`); - }); - }).catch(function(err) { - console.log(err); - return message.channel.send(":x: Error! Something went wrong!"); + try { + let response = await request + .get('http://jservice.io/api/random') + .query({ + count: 1 }); - }); + const embed = new Discord.RichEmbed() + .setTitle('You have **fifteen** seconds to answer this question:') + .setDescription(`**Category: ${response.body[0].category}**\n${response.body[0].question}`); + let embededMessage = await message.channel.sendEmbed(embed); + try { + let collected = await message.channel.awaitMessages(res => res.content.toLowerCase() === response.body[0].answer.toLowerCase() && res.author.id === message.author.id, { + max: 1, + time: 15000, + errors: ['time'] + }); + let winnerMes = await message.channel.send(`Good Job! You won!`); + } + catch (err) { + let loserMes = await message.channel.send(`Aw... Too bad, try again next time!\nThe Correct Answer was: ${response.body[0].answer}`); + } + } + catch (err) { + let errorMessage = await message.channel.send(":x: Error! Something went wrong!"); + } } -}; \ No newline at end of file +};