diff --git a/commands/search/recipe.js b/commands/search/recipe.js index d075d21c..c90a07f2 100644 --- a/commands/search/recipe.js +++ b/commands/search/recipe.js @@ -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.'); + } } }; diff --git a/package.json b/package.json index e139d170..692651df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "27.1.1", + "version": "27.1.2", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {