Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //npm install ffmpeg-binaries
  2. //npm install ytdl-core
  3. //npm install node-opus
  4. //npm install opusscript
  5.  
  6. const ytdl = require('ytdl-core');
  7.  
  8. exports.run = async (client, message, args, ops) => {
  9.     client.on("error", (e) => console.error(e));
  10.   client.on("warn", (e) => console.warn(e));
  11.   client.on("debug", (e) => console.info(e));
  12.  
  13.     require('events').EventEmitter.prototype._maxListeners = 10000;
  14.    
  15.    
  16.     if (!message.member.voiceChannel) return message.channel.send('Please connect to a voice channel.');
  17.    
  18.     if (!args[0]) return message.channel.send('Sorry, please input a url following the command.');
  19.  
  20.     let validate = await ytdl.validateURL(args[0]);
  21.    
  22.    
  23.  
  24.     if (!validate) {
  25.  
  26.         let commandFile = require(`./search.js`);
  27.         return commandFile.run(client, message, args, ops);
  28.  
  29.     }
  30.  
  31.     let info = await ytdl.getInfo(args[0]);
  32.  
  33.     let data = ops.active.get(message.guild.id) || {};
  34.  
  35.     if (!data.connection) data.connection = await message.member.voiceChannel.join();
  36.     if (!data.queue) data.queue = [];
  37.     data.guildID = message.guild.id;
  38.  
  39.     data.queue.push({
  40.         songTitle: info.title,
  41.         requester: message.author.tag,
  42.         url: args[0],
  43.         announceChannel: message.channel.id
  44.     });
  45.  
  46.     if (!data.dispatcher) play(client, ops, data);
  47.     else {
  48.  
  49.         message.channel.send(`Added To Queue: ${info.title} | Requested By: ${message.author.id}`);
  50.     }
  51.  
  52.     ops.active.set(message.guild.id, data);
  53.  
  54. }
  55.  
  56. async function play(client, ops, data) {
  57.  
  58.     client.channels.get(data.queue[0].announceChannel).send(`Now Playing: ${data.queue[0].songTitle} | Requested By: ${data.queue[0].requester}`);
  59.  
  60.     data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].url, { filter: 'audioonly' }));
  61.     data.dispatcher.guildID = data.guildID;
  62.  
  63.     data.dispatcher.once('end', function() {
  64.         finish(client, ops, this);
  65.     });
  66. }
  67.  
  68. function finish(client, ops, dispatcher) {
  69.  
  70.     let fetched = ops.active.get(dispatcher.guildID);
  71.  
  72.     fetched.queue.shift();
  73.  
  74.     if (fetched.queue.length > 0) {
  75.  
  76.         ops.active.set(dispatcher.guildID, fetched);
  77.  
  78.         play(client, ops, fetched);
  79.  
  80.     } else {
  81.  
  82.         ops.active.delete(dispatcher.guildID);
  83.  
  84.         let vc = client.guilds.get(dispatcher.guildID).me.voiceChannel;
  85.         if (vc) vc.leave();
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement