SHARE
TWEET

Untitled

a guest Sep 27th, 2019 1,056 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const {
  2.     Client,
  3.     Attachment
  4. } = require('discord.js');
  5. const bot = new Client();
  6.  
  7. const cheerio = require('cheerio');
  8.  
  9. const request = require('request');
  10.  
  11.  
  12.  
  13. const token = 'YOUR TOKEN';
  14.  
  15. const PREFIX = '!';
  16.  
  17. var version = '1.3';
  18.  
  19.  
  20. bot.on('ready', () => {
  21.     console.log('This bot is online! ' + version);
  22.  
  23. })
  24.  
  25.  
  26.  
  27.  
  28. bot.on('message', message => {
  29.  
  30.     let args = message.content.substring(PREFIX.length).split(" ");
  31.  
  32.     switch (args[0]) {
  33.         case 'image':
  34.         image(message);
  35.  
  36.         break;
  37.     }
  38.  
  39. });
  40.  
  41. function image(message){
  42.  
  43.     var options = {
  44.         url: "http://results.dogpile.com/serp?qc=images&q=" + "food",
  45.         method: "GET",
  46.         headers: {
  47.             "Accept": "text/html",
  48.             "User-Agent": "Chrome"
  49.         }
  50.     };
  51.  
  52.  
  53.  
  54.  
  55.  
  56.     request(options, function(error, response, responseBody) {
  57.         if (error) {
  58.             return;
  59.         }
  60.  
  61.  
  62.         $ = cheerio.load(responseBody);
  63.  
  64.  
  65.         var links = $(".image a.link");
  66.  
  67.         var urls = new Array(links.length).fill(0).map((v, i) => links.eq(i).attr("href"));
  68.        
  69.         console.log(urls);
  70.  
  71.         if (!urls.length) {
  72.            
  73.             return;
  74.         }
  75.  
  76.         // Send result
  77.         message.channel.send( urls[Math.floor(Math.random() * urls.length)]);
  78.     });
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. }
  88.  
  89. bot.login(token);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top