diff --git a/bot.js b/bot.js index ad636bd..bbc0acc 100644 --- a/bot.js +++ b/bot.js @@ -130,7 +130,8 @@ function imgurRequest(subreddit, page_max) { if (req.responseText !== "Not found") { try { var json = JSON.parse(req.responseText); - returnText = json.data[getRandomInt(0, json.data.length - 1)].link; + let json_data = json.data[getRandomInt(0, json.data.length - 1)]; + if(json_data) { returnText = json_data.link; } } catch (error) { // Ignore the error and let the calling method handle the empty string. }