title: How to make an Array for Google Images Discord js?
body: <pre class="lang-js prettyprint-override"><code>const request = require('request');
  const cheerio = require('cheerio');
  const Discord = require('discord.js');
  
  const client = new Discord.Client();
  const token = ' .....';
  const prefix = '-';
  
  client.login(token);
  
  client.on('message', (message) =&gt; {
   const image2 = message.content.slice(1);
   let args = message.content.substring(prefix.length).split(' ');
  
   switch (args[0]) {
    case 'random':
     image(message);
     break;
   }
  });
  
  function image(message) {
   const image2 = message.content.slice(7);
  
   var options = {
    url: 'http://results.dogpile.com/serp?qc=images&amp;q=' + image2,
    method: 'GET',
    headers: {
     Accept: 'text/html',
     'User-Agent': 'Chrome',
    },
   };
  
   if (!image2)
    var options = {
     url: 'http://www.google.com/images?q=' + 'cursed+images',
     method: 'GET',
     headers: {
      Accept: 'text/html',
      'User-Agent': 'Chrome',
     },
    };
  
   request(options, function(error, response, responseBody) {
    if (error) {
     return;
    }
  
    $ = cheerio.load(responseBody);
  
    var links = $('.image a.link');
  
    var urls = new Array(links.length)
     .fill(0)
     .map((v, i) =&gt; links.eq(i).attr('href'));
  
    console.log(urls);
  
    if (!urls.length) {
     return;
    }
  
    // Send result
    message.channel.send(urls[Math.floor(Math.random() * urls.length)]);
   });
  }
  </code></pre>
  <p>Okay so i tried to get a random searched image to be shown in discord by my bot,
  the function to get an Array for &quot;results.dogpile.com&quot; works
  example : -image dog ( i get a dog image from choosing a random link from Array of result.dogpile.com</p>
  <p>If i try : -image ( it doesn't show anything , due to the fact that the Array was made for results.dogpile not for google images user interface )</p>
  <p>The question is ... how should i make the Array for google images to get a random image from search ?</p>