Try Catch Error

This commit is contained in:
Daniel Odendahl Jr
2017-06-15 03:36:18 +00:00
parent 5524cfadd6
commit 9c733202db
+16 -5
View File
@@ -1,6 +1,7 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const snekfetch = require('snekfetch'); const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags'); const { stripIndents } = require('common-tags');
const { WORDNIK_KEY } = process.env;
module.exports = class HangmanCommand extends Command { module.exports = class HangmanCommand extends Command {
constructor(client) { 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.'); if (this.playing.has(msg.guild.id)) return msg.say('Only one game may be occurring per server.');
this.playing.add(msg.guild.id); this.playing.add(msg.guild.id);
try { try {
const { text } = await snekfetch const { body } = await snekfetch
.get('http://setgetgo.com/randomword/get.php'); .get('http://api.wordnik.com:80/v4/words.json/randomWord')
const word = text.toLowerCase().replace(/[ ]/g, '-'); .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; let points = 0;
const confirmation = []; const confirmation = [];
const incorrect = []; const incorrect = [];
@@ -66,7 +77,7 @@ module.exports = class HangmanCommand extends Command {
else return msg.say(`Too bad... It was ${word}...`); else return msg.say(`Too bad... It was ${word}...`);
} catch (err) { } catch (err) {
this.playing.delete(msg.guild.id); 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}\``);
} }
} }
}; };