I have been messing around with image scraper (discord.js v13).
I would love to make it so everytime i do for example ?image car it sends different picture of car.
This is my code rn, its just basic plain scraper
const google = new Scraper({
puppeteer: {
headless: true,
},
});
module.exports = {
name: 'image',
description: 'Send picture (possibly automatically maybe)',
async execute( kaoru, message, args, Discord){
const image_query = args.join(' ');
if(!image_query) return message.channel.send('> **Please enter name of the image!**');
const image_results = await google.scrape(image_query, 50);
message.channel.send(image_results[0].url)
}
}```
Any ideas?
I tried to google help, but didnt find anything. Also i think it has something to do with this part: ```message.channel.send(image_results[0].url)``` Because if i change [0] to [2] for example, it changes that pic. But it would be cool if it would send pics between 0-100
You can use a randomizer to set the value in image_results. Like this:
image_results[Math.floor(Math.random() * 50)].url
That should give you a random integer between 0 and 49 (js index starts at 0).