Fix undefined

This commit is contained in:
Daniel Odendahl Jr
2017-10-17 21:06:49 +00:00
parent e3efb1b964
commit cf7e741dd1
+4 -1
View File
@@ -29,7 +29,10 @@ module.exports = class AnagramCommand extends Command {
try {
const { body } = await snekfetch.get(`http://www.anagramica.com/best/${word}`);
if (!body.best.length) return msg.say('Could not find any results.');
const words = strict ? body.best.filter(anagram => anagram.length === word.length) : body.best;
const all = body.best.filter(anagram => anagram.toLowerCase() !== word);
if (!all.length) return msg.say('Could not find any results.');
const words = strict ? all.filter(anagram => anagram.length === word.length) : all;
if (!words.length) return msg.say('Could not find any results.');
return msg.say(words[Math.floor(Math.random() * words.length)]);
} catch (err) {
if (err.status === 500) return msg.say('Could not find any results.');