Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bot.on("message", msg => {
  2.     let prefix = "!";
  3.     if (!msg.content.startsWith(prefix)) return;
  4.     const voiceChannel = msg.member.voiceChannel;
  5.     if (msg.content.startsWith(prefix + "summon")) {
  6.         if (!voiceChannel) return msg.channel.send("Connect to a channel first");
  7.         msg.member.voiceChannel.join();
  8.         msg.channel.send("using !summon before !play is not nessecary");
  9.     }
  10.     if (msg.content.startsWith(prefix + "play") || msg.content.startsWith(prefix + "yt")) {
  11.         if (!voiceChannel) return msg.channel.send("Connect to a channel first");
  12.         msg.member.voiceChannel.join().then(connection => {
  13.             var rest = msg.content.split(" ");
  14.             rest.splice(0, 1);
  15.             rest = rest.join(" ");
  16.             youtube.setKey(key);
  17.             youtube.search(rest, 2, function(error, result) {
  18.                 if (error) {
  19.                     return console.log('bad link');
  20.                     //    console.log(error);
  21.                 } else {
  22.                     if (JSON.stringify(result.items[0]) == undefined) {
  23.                         return msg.channel.send("bad link");
  24.                     } else {
  25.                         title = JSON.stringify(result.items[0].snippet.title);
  26.                         url = result.items[0].id.videoId;
  27.                         song[0] = 'https://www.youtube.com/watch?v=' + url;
  28.                         if (url === undefined) {
  29.                             return msg.channel.send("bad link");
  30.                         } else {
  31.                             (function playSong(currentSong) {
  32.                                 dispatcher = connection.playStream(yt(currentSong, {
  33.                                     audioonly: true
  34.                                 }), {
  35.                                     passes: 1
  36.                                 });
  37.                                 let collector = msg.channel.createCollector(m => m);
  38.                                 collector.on('collect', m => {
  39.                                     if (m.content.startsWith(prefix + "pause")) {
  40.                                         if (dispatcher === undefined) {
  41.                                             return msg.channel.send("nothing to pause");
  42.                                         } else {
  43.                                             msg.channel.send("paused!");
  44.                                             dispatcher.pause();
  45.                                         }
  46.                                     }
  47.  
  48.                                     if (m.content.startsWith(prefix + "skip")) {
  49.                                         if (dispatcher !== undefined) {
  50.                                          collector.stop();
  51.                                             dispatcher.end();
  52.                 }    else return msg.channel.send("nothing to skip");
  53.                                     }
  54.                                     if (m.content.startsWith(prefix + "resume")) {
  55.                                         if (dispatcher !== undefined) {
  56.                                             dispatcher.resume();
  57.                                             msg.channel.send("resumed!");
  58.                                         } else return msg.channel.send("nothing to resume");
  59.                                     }
  60.                                 });
  61.                                 dispatcher.on('end', () => {
  62.                                     console.log("ended");
  63.                                     collector.stop();
  64.  
  65.                                     bot.user.setPresence({
  66.                                         game: {
  67.                                             name: 'Type !help For Commands',
  68.                                             type: 0
  69.                                         }
  70.                                     });
  71.  
  72.  
  73.                                 });
  74.  
  75.                                 msg.channel.send("playing " + title);
  76.                                 console.log("Downloading" + " - " + title);
  77.                                 bot.user.setPresence({
  78.                                     game: {
  79.                                         name: title,
  80.                                         type: 0
  81.                                     }
  82.                                 });
  83.                             })(song[0]);
  84.  
  85.                         }
  86.                     }
  87.                 }
  88.             });
  89.         });
  90.  
  91.     }
  92.     if (msg.content.startsWith(prefix + "add")) {
  93.         if (!voiceChannel) return msg.channel.send("Connect to a channel first");
  94.         var rest = msg.content.split(" ");
  95.         rest.splice(0, 1);
  96.         rest = rest.join(" ");
  97.         youtube.setKey(key);
  98.         youtube.search(rest, 2, function(error, result2) {
  99.             title = JSON.stringify(result2.items[0].snippet.title);
  100.             url = result2.items[0].id.videoId;
  101.             queue = 'https://www.youtube.com/watch?v=' + url;
  102.             if (url === undefined) {
  103.                 return msg.channel.send("bad link");
  104.             } else {
  105.                 song.push(queue);
  106.                 song.shift();
  107.                 msg.channel.send("added to queue!");
  108.                 console.log("Added" + " - " + title);
  109.             }
  110.         });
  111.     }
  112.  
  113.     if (msg.content.startsWith(prefix + "clean")) {
  114.         var rest = msg.content.split(" ");
  115.         rest.splice(0, 1);
  116.         rest = rest.join(" ");
  117.         if (isNaN(rest) === false && rest < 100) {
  118.             msg.channel.bulkDelete(rest);
  119.         } else {
  120.             msg.channel.send("Bot can only clean a value of 1 - 100 messages");
  121.         }
  122.         console.log(msg.author.username + " deleted " + rest + " messages");
  123.     }
  124.     if (msg.content.startsWith(prefix + "ip")) {
  125.         msg.author.send('braydenserver.serveftp.com');
  126.         msg.channel.send("IP has been direct messaged");
  127.         console.log(msg.author.username + " requested the ip")
  128.     }
  129.     if (msg.content.startsWith(prefix + "help")) {
  130.         msg.channel.send(" commands: \n \n \
  131.       summon = Summons the bot to a voice channel \n \
  132.       play + URL or yt + URL = joins voice channel and plays the url the user requested \n \
  133.       puase = Puases current song \n \
  134.       Skip = Skips to next song in queue \n \
  135.       resume = Resumes current song in queue \n \
  136.       add + URL = Appends the URL to the end of the queue \n \
  137.       queue = Puts the songs that are currently in queue into the chat \n \
  138.       clear = Deletes every song from queue \n \
  139.       clean + Number = deletes however many messages (specified by number -1 because of bug) \n \
  140.       leave = Bot leaves voice chat \n \
  141.       ping = pong \n \
  142.       ip = direct messages the ip in the form of a dns or url \
  143.       ");
  144.     }
  145.     if (msg.content.startsWith(prefix + "leave")) {
  146.         if (!msg.guild.member(bot.user).voiceChannel) {
  147.             return (msg.channel.send("Bot is not summoned!"))
  148.         } else {
  149.             msg.guild.member(bot.user).voiceChannel.leave();
  150.         }
  151.     }
  152.     if (msg.content.startsWith(prefix + "ping")) {
  153.         msg.channel.send("pong!");
  154.     }
  155.     if (msg.content.startsWith(prefix + "queue")) {
  156.         if (song[1] !== undefined) {
  157.             msg.channel.send(song);
  158.         } else return msg.channel.send("Nothing in queue. !add to add a song to queue");
  159.     }
  160.     if (msg.content.startsWith(prefix + "clear")) {
  161.         if (song !== undefined) {
  162.             song = [];
  163.             msg.channel.send("Queue has been cleared");
  164.         } else return msg.channel.send("The queue is already empty");
  165.     }
  166. });
  167.  
  168.  
  169. bot.on('ready', () => {
  170.     bot.user.setPresence({
  171.         game: {
  172.             name: 'Type !help For Commands',
  173.             type: 0
  174.         }
  175.     });
  176.     console.log('Bot is online');
  177. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement