mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
Try Catch Error
This commit is contained in:
@@ -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}\``);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user