From 8f12d5f9a1d5489c86c8db7476b4759c30df5c8d Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 28 Sep 2018 13:08:53 +0200 Subject: [PATCH] Dosent get stuck in while loop ( i think ) --- commands/fun/reddit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/fun/reddit.js b/commands/fun/reddit.js index 1d09466..32bd257 100644 --- a/commands/fun/reddit.js +++ b/commands/fun/reddit.js @@ -21,11 +21,13 @@ module.exports = class redditCommand extends Command { async run(message, { sub }) { const { body } = await snekfetch.get('https://www.reddit.com/r/' + sub + '.json?limit=100'); let /* the bodies hit the floor */ i = Math.floor((Math.random() * 10) + 1); + let a = 0 if (!body.data.children[1]) { return message.say('Not a valid subreddit') } - while (body.data.children[i].data.post_hint !== 'image') { + while (body.data.children[i].data.post_hint !== 'image' || a == 5) { i = Math.floor((Math.random() * 100) + 1); + a++ } if (body.data.children[i].data.over_18 == true) { return message.say("No nsfw ( if you want a nsfw version of this commands use the feedback commands \"haha feedback \")")