Advertisement
Guest User

my script dont ask

a guest
Apr 3rd, 2020
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     if(message.content.startsWith('!search')) {
  2.         var args = message.content.split(' '); args.shift()
  3.  
  4.         var options = {
  5.             url: "https://www.google.com/search?q=" + args.join(' '),
  6.             method: "GET",
  7.             headers: {
  8.                 "Accept": "text/html",
  9.                 "User-Agent": "Chrome"
  10.             }
  11.         };
  12.  
  13.         console.log(options.url)
  14.  
  15.         request(options, function(error, response, responseBody) {
  16.             if (error) {
  17.                 console.log(error)
  18.                 return message.channel.send('An error has occured! Please tell the developer to check the console!')
  19.             }
  20.      
  21.      
  22.             $ = cheerio.load(responseBody);
  23.      
  24.      
  25.             var links = $(".image a.link");
  26.      
  27.             var urls = new Array(links.length).fill(0).map((v, i) => links.eq(i).attr("href"));
  28.            
  29.             console.log(urls);
  30.      
  31.             if (!urls.length) {  
  32.                 return;
  33.             }
  34.      
  35.             // Send result
  36.             message.channel.send( urls[Math.floor(Math.random() * urls.length)]);
  37.         });
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement