Filter only valid images

This commit is contained in:
Daniel Odendahl Jr
2017-09-29 21:55:16 +00:00
parent a5040e63f1
commit b3bc04f056
+1 -1
View File
@@ -26,7 +26,7 @@ module.exports = class ImgurCommand extends Command {
.get('https://api.imgur.com/3/gallery/search')
.query({ q: query })
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
const images = msg.channel.nsfw ? body.data : body.data.filter(image => !image.nsfw);
const images = body.data.filter(image => image.images && (msg.channel.nsfw ? true : !image.nsfw));
if (!images.length) return msg.say('Could not find any results.');
return msg.say(images[Math.floor(Math.random() * images.length)].images[0].link);
} catch (err) {