From 8db51f2fe83b3635772cf9ede2aa89c9fe128792 Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sun, 15 Dec 2019 18:39:32 +0100 Subject: [PATCH] handle 404 and if the response.data contain nothing --- commands/fun/reddit.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commands/fun/reddit.js b/commands/fun/reddit.js index 175ec96b..a8118555 100644 --- a/commands/fun/reddit.js +++ b/commands/fun/reddit.js @@ -36,7 +36,11 @@ class RedditCommand extends Command { fetch('https://www.reddit.com/r/' + args.sub + '.json?limit=100').then((response) => { return response.json(); }).then((response) => { - if (!response.data) + console.log(response); + if (response.error == 404) + return message.channel.send('Not a valid subreddit'); + + if (response.data.dist == 0) return message.channel.send('Not a valid subreddit'); let i = Math.floor((Math.random() * response.data.children.length));