Try/Catch recipe

This commit is contained in:
Daniel Odendahl Jr
2017-07-11 18:09:54 +00:00
parent 87b2f18803
commit c6ad2e8061
2 changed files with 19 additions and 15 deletions
+18 -14
View File
@@ -21,19 +21,23 @@ module.exports = class RecipeCommand extends Command {
}
async run(msg, args) {
const { query } = args;
const { text } = await snekfetch
.get('http://www.recipepuppy.com/api/')
.query({ q: query });
const body = JSON.parse(text);
if (!body.results.length) return msg.say('No Results.');
const recipe = body.results[Math.floor(Math.random() * body.results.length)];
const embed = new MessageEmbed()
.setColor(0xC20000)
.setURL(recipe.href)
.setTitle(recipe.title)
.setDescription(`**Ingredients:** ${recipe.ingredients}`)
.setThumbnail(recipe.thumbnail);
return msg.embed(embed);
try {
const { query } = args;
const { text } = await snekfetch
.get('http://www.recipepuppy.com/api/')
.query({ q: query });
const body = JSON.parse(text);
if (!body.results.length) return msg.say('No Results.');
const recipe = body.results[Math.floor(Math.random() * body.results.length)];
const embed = new MessageEmbed()
.setColor(0xC20000)
.setURL(recipe.href)
.setTitle(recipe.title)
.setDescription(`**Ingredients:** ${recipe.ingredients}`)
.setThumbnail(recipe.thumbnail);
return msg.embed(embed);
} catch (err) {
return msg.say('No Results.');
}
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "27.1.1",
"version": "27.1.2",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {