Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const ytdl = require('ytdl-core');
  2.  
  3. async function play(bot, ops, data){
  4.  
  5.   bot.channels.get(data.queue[0].message_channel).send(`Now Playing ${data.queue[0].songTitle} requested by ${data.queue[0].requester}}`)
  6.  
  7.   data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].song, { filter: 'audioonly' }));
  8.  
  9.   data.dispatcher.guildID = data.guildID;
  10.  
  11.   data.dispatcher.once('end', function(){
  12.  
  13.     finish(bot, ops, this);
  14.    
  15.   })
  16. }
  17. function finish(bot, ops, dispatcher){
  18.  
  19.   let fetched = ops.queue.get(dispatcher.guildID);
  20.  
  21.   fetched.queue.shift();
  22.  
  23.   if(fetched.queue.length > 0){
  24.  
  25.     ops.queue.set(dispatcher.guildID, fetched)
  26.    
  27.     play(bot, ops, fetched)
  28.  
  29.   }
  30.   else {
  31.  
  32.     ops.queue.delete(dispatcher.guildID);
  33.    
  34.     let vc = bot.guilds.get(dispatcher.guildID).me.voiceChannel;
  35.    
  36.     if (vc) {vc.leave()}
  37.    
  38.  
  39.   }
  40.  
  41. }
  42.  
  43. module.exports.run = async (bot, message, args, ops) => {
  44.  
  45.   try {
  46.  
  47.     if(!message.member.voiceChannel){return(message.channel.send('ERROR: You need to be connected to a voice channel!'));}
  48.    
  49.     if(!args[0]){return(message.channel.send('ERROR Please Enter a song/video you want to play.'));}
  50.    
  51.     let validate = await ytdl.validateURL(args[0]);
  52.    
  53.     if(!validate){
  54.    
  55.       let commandFile = require('./search.js')
  56.       return(commandFile.run(bot,message,args,ops))
  57.    
  58.     }
  59.  
  60.     let info = await ytdl.getInfo(args[0])
  61.    
  62.     let data = ops.queue.get(message.guild.id) || {};
  63.    
  64.     if(!data.connection){data.connection = await message.member.voiceChannel.join();}
  65.    
  66.     if(!data.queue){data.queue = []}
  67.                    
  68.     data.guildID = message.guild.id;
  69.  
  70.     data.queue.push({
  71.  
  72.       songTitle: info.title,
  73.       requester: message.author.tag,
  74.       song: args[0],
  75.       message_channel: message.channel.id
  76.  
  77.     });
  78.    
  79.     if(!data.dispatcher){
  80.    
  81.       play(bot, ops, data)
  82.      
  83.       message.guild.me.setMute(false).catch(() => {});
  84.       message.guild.me.setDeaf(true).catch(() => {});
  85.     }
  86.     else{
  87.    
  88.       message.channel.send(`Added to queue: ${info.title}`)
  89.    
  90.     }
  91.    
  92.     ops.queue.set(message.guild.id, data)
  93.    
  94.   }
  95.   catch (err) {
  96.  
  97.     console.log(err);
  98.     return(message.channel.send('ERROR: AN unexpected error has occured please contact a developer'))
  99.  
  100.   }
  101.    
  102. }
  103.  
  104. module.exports.help = {
  105.  
  106.   name: "play",
  107.   description: "Usage: Plays Music. Command: <prefix>play <URL or Search Query>"
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement