mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Try/Catch recipe
This commit is contained in:
+18
-14
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiaobot",
|
||||
"version": "27.1.1",
|
||||
"version": "27.1.2",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Shard.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user