From 9c733202db56ddfdcf9f374668bdbdba15f74a22 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 15 Jun 2017 03:36:18 +0000 Subject: [PATCH] Try Catch Error --- commands/games/hangman.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/commands/games/hangman.js b/commands/games/hangman.js index a6ccd55f..1c0111e0 100644 --- a/commands/games/hangman.js +++ b/commands/games/hangman.js @@ -1,6 +1,7 @@ const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const { stripIndents } = require('common-tags'); +const { WORDNIK_KEY } = process.env; module.exports = class HangmanCommand extends Command { constructor(client) { @@ -19,9 +20,19 @@ module.exports = class HangmanCommand extends Command { if (this.playing.has(msg.guild.id)) return msg.say('Only one game may be occurring per server.'); this.playing.add(msg.guild.id); try { - const { text } = await snekfetch - .get('http://setgetgo.com/randomword/get.php'); - const word = text.toLowerCase().replace(/[ ]/g, '-'); + const { body } = await snekfetch + .get('http://api.wordnik.com:80/v4/words.json/randomWord') + .query({ + hasDictionaryDef: true, + minCorpusCount: 0, + maxCorpusCount: -1, + minDictionaryCount: 1, + maxDictionaryCount: -1, + minLength: -1, + maxLength: -1, + api_key: WORDNIK_KEY + }); + const word = body.word.toLowerCase().replace(/[ ]/g, '-'); let points = 0; const confirmation = []; const incorrect = []; @@ -66,7 +77,7 @@ module.exports = class HangmanCommand extends Command { else return msg.say(`Too bad... It was ${word}...`); } catch (err) { this.playing.delete(msg.guild.id); - return msg.say(`An Error Occurred during the command: ${err.message}`); + return msg.say(`Oh no, an Error occurred! Try again later! \`${err.name}: ${err.message}\``); } } -}; +}; \ No newline at end of file