SHARE
TWEET

Untitled

a guest Nov 21st, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const Config = require("./config.json");
  3. const Token = require("./token.json");
  4. const Prefix = "1";
  5. const Client = new Discord.Client({disableEveryone: true});
  6. const Cheerio = require('cheerio');
  7. const Request = require('request');
  8.  
  9. Client.on("ready", () => {
  10.   // This event will run if the Client starts, and logs in, successfully.
  11.   console.log(`Client has started, with ${Client.users.size} users, in ${Client.channels.size} channels of ${Client.guilds.size} guilds.`);
  12.   // Example of changing the Client's playing game to something useful. `Client.user` is what the
  13.   // docs refer to as the "ClientUser".
  14.   Client.user.setActivity(`lapam na ${Client.guilds.size} servers`);
  15. });
  16.  
  17. Client.on('message', message=>{
  18.   let args = message.content.substring(Prefix.length).split(" ")
  19.   switch(args[0]){
  20.     case 'yo':
  21.     message.channel.send('angelo');
  22.     break;
  23.     case'tolga':
  24.     message.channel.send('https://imgur.com/a/R8ThqyQ')
  25.     break;
  26.   }
  27. })
  28.  
  29.  
  30. Client.on('message', message => {
  31.  
  32.     let args = message.content.substring(Prefix.length).split(" ");
  33.  
  34.     switch (args[0]) {
  35.         case 'image':
  36.         image(message);
  37.  
  38.         break;
  39.     }
  40.  
  41. });
  42.  
  43. function image(message){
  44.  
  45.     var options = {
  46.         url: "http://results.dogpile.com/serp?qc=images&q=" + "memes",
  47.         method: "GET",
  48.         headers: {
  49.             "Accept": "text/html",
  50.             "User-Agent": "Chrome"
  51.         }
  52.     };
  53.  
  54.  
  55.  
  56.  
  57.  
  58.     Request(options, function(error, response, responseBody) {
  59.         if (error) {
  60.             return;
  61.         }
  62.  
  63.  
  64.         $ = Cheerio.load(responseBody);
  65.  
  66.  
  67.         var links = $(".image a.link");
  68.  
  69.         var urls = new Array(links.length).fill(0).map((v, i) => links.eq(i).attr("href"));
  70.  
  71.         console.log(urls);
  72.  
  73.         if (!urls.length) {
  74.  
  75.             return;
  76.         }
  77.  
  78.         // Send result
  79.         message.channel.send( urls[Math.floor(Math.random() * urls.length)]);
  80.     });
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. }
  90.  
  91.  
  92. Client.login(Token.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