Make Achievements ourselves

This commit is contained in:
Daniel Odendahl Jr
2017-10-15 15:32:21 +00:00
parent 1c951c0850
commit 0b2664c1f8
5 changed files with 23 additions and 21 deletions
+3 -2
View File
@@ -26,8 +26,9 @@ module.exports = class NASACommand extends Command {
const { body } = await snekfetch
.get('https://images-api.nasa.gov/search')
.query({ q: query });
if (!body.collection.items.length) return msg.say('Could not find any results.');
const data = body.collection.items[Math.floor(Math.random() * body.collection.items.length)];
const filtered = body.collection.items.filter(item => item.data[0].media_type === 'image');
if (!filtered.length) return msg.say('Could not find any results.');
const data = filtered[Math.floor(Math.random() * filtered.length)];
return msg.say(shorten(data.data[0].description), { files: [data.links[0].href] });
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);