From 00bdddaf244ab24a8d1f7c153d1dd303935c57b5 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 28 Sep 2018 18:04:31 +0200 Subject: [PATCH] Post no longer hardcoded --- commands/fun/reddit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/fun/reddit.js b/commands/fun/reddit.js index f40810e..e741417 100644 --- a/commands/fun/reddit.js +++ b/commands/fun/reddit.js @@ -23,11 +23,12 @@ module.exports = class redditCommand extends Command { let a = 0 fetch('https://www.reddit.com/r/' + sub + '.json?limit=100').then((response) => { return response.json(); - }).then((response) => { + }).then((response) => { if (!response.data) return message.say('Not a valid subreddit') while (response.data.children[i].data.post_hint !== 'image') { - i = Math.floor((Math.random() * 100) + 1); + i = Math.floor((Math.random() * response.data.children.length)); + a++ if (a == 5) return message.say("Could not find any images")