cant get stuck in while anymore ( i think )

This commit is contained in:
unknown 2018-09-28 00:39:34 +02:00
parent 1121f92ca6
commit c2a6ebbf33

View file

@ -19,13 +19,17 @@ module.exports = class redditCommand extends Command {
} }
async run(message, { sub }) { async run(message, { sub }) {
const { body } = await snekfetch.get('https://www.reddit.com/r/' + sub + '.json?limit=100'); 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 /* the bodies hit the floor */ i = Math.floor((Math.random() * 10) + 1);
let a = 0
if (!body.data.children[1]) { if (!body.data.children[1]) {
return message.say('Not a valid subreddit') return message.say('Not a valid subreddit')
} else if (!body.data.children[i].data) {
return console.log('please try again')
} }
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); i = Math.floor((Math.random() * 100) + 1);
a++
} }
if (body.data.children[i].data.over_18 == true) { 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 <your feedback>\")") return message.say("No nsfw ( if you want a nsfw version of this commands use the feedback commands \"haha feedback <your feedback>\")")