don't check json if reddit doesn't exist
This commit is contained in:
2
bot.js
2
bot.js
@@ -186,6 +186,7 @@ function imgurRequest(subreddit, page_max) {
|
|||||||
// Abstracted Reddit Json media grab.
|
// Abstracted Reddit Json media grab.
|
||||||
function handleRedditJson(data) {
|
function handleRedditJson(data) {
|
||||||
let json = data.json();
|
let json = data.json();
|
||||||
|
if(json.data.children) {
|
||||||
for (let i = 0; i < json.data.children.length; i++) {
|
for (let i = 0; i < json.data.children.length; i++) {
|
||||||
let rand = getRandomInt(0, json.data.children.length - 1);
|
let rand = getRandomInt(0, json.data.children.length - 1);
|
||||||
|
|
||||||
@@ -193,6 +194,7 @@ function handleRedditJson(data) {
|
|||||||
return json.data.children[rand].data.url;
|
return json.data.children[rand].data.url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// What if we don't find anything i.e. r/dogs but its valid subreddit.
|
// What if we don't find anything i.e. r/dogs but its valid subreddit.
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user