Skip to content

Commit

Permalink
Fixed bug where bot would crash when no image could be found
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakhar896 committed May 31, 2021
1 parent 1a2748d commit efb0cb1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion commands/gi.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ module.exports = {
msg.reply(`Please wait a second while I get a random image from online, with the subject **${image_query}**`)

const image_results = await google.scrape(image_query, 200);
msg.channel.send(image_results[Math.floor((Math.random() * image_results.length) + 1)].url)
var img = image_results[Math.floor((Math.random() * image_results.length) + 1)]
if (img) {
msg.channel.send(img.url)
.catch(err => {
console.log('Error in sending URL of image: ' + err)
})
} else {
msg.channel.send('Sorry, could not find an image on that query.')
}
return
}
}

0 comments on commit efb0cb1

Please sign in to comment.