handle 404 and if the response.data contain nothing
This commit is contained in:
parent
aab7ce97a5
commit
8db51f2fe8
1 changed files with 5 additions and 1 deletions
|
@ -36,7 +36,11 @@ class RedditCommand extends Command {
|
||||||
fetch('https://www.reddit.com/r/' + args.sub + '.json?limit=100').then((response) => {
|
fetch('https://www.reddit.com/r/' + args.sub + '.json?limit=100').then((response) => {
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then((response) => {
|
}).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');
|
return message.channel.send('Not a valid subreddit');
|
||||||
|
|
||||||
let i = Math.floor((Math.random() * response.data.children.length));
|
let i = Math.floor((Math.random() * response.data.children.length));
|
||||||
|
|
Loading…
Reference in a new issue