Previously I had figured out how to send images, based on the arguments, now I have updated the command to a different command handler and it doesn't send anything. The error in the console says :
ErrorClass [HTTPError]: Response code 403 (Forbidden)
at C:\Users\infec\Desktop\Uni Beta\node_modules\google-images\node_modules\got\index.js:123:13
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
host: 'www.googleapis.com',
hostname: 'www.googleapis.com',
method: 'GET',
path: '/customsearch/v1?q=summer&searchType=image&cx=91069a4e85b6cd0e0&key=AIzaSyCTOYK4lo7uEr59H___PPH5d7e3kAk3OnY',
statusCode: 403,
statusMessage: 'Forbidden'
}
const Discord = require('discord.js');
const GoogleImages = require('google-images');
module.exports = {
name: 'pic',
description: 'Sends A Picture Depending On Arguments',
async run(client, message, args, cseid, apikeygoogle, prefix) {
const client2 = new GoogleImages(cseid, apikeygoogle)
var term = args.join(" ")
if (term) {
client2.search(`${term}`)
.then(images => {
const randomIndex = Math.floor(Math.random() * images.length);
message.channel.send({ files: [images[randomIndex].url] });
})
.catch((err) => {
message.channel.send('Error')
console.log(err)
})
}
}
}