Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const ytsearch = require("yt-search");
  3. const ffmpeg = require("ffmpeg");
  4. const ytdl = require("ytdl-core");
  5. const config = require("../config.json");
  6.  
  7. module.exports.run = async (bot, message, args, opts) => {
  8.   if(!message.member.voiceChannel) return message.channel.send("You must be connected to a voice chat to run this command.");
  9.   if(message.guild.me.voiceChannel) return message.channel.send("I am already connected to a voice chat!");
  10.   if(!args[0]) return message.channel.send("Please provide a URL.");
  11.  
  12.   let valid = await ytdl.validateURL(args[0]);
  13.   if(!valid) return message.channel.send("Please provide a valid URL.");
  14.  
  15.   let info = await ytdl.getInfo(args[0]);
  16.   let connect = await message.member.voiceChannel.join();
  17.   let dp = await connect.playStream(ytdl(args[0], {filter: 'audio' }));
  18.  
  19.   message.channel.send(`🎵 Now Playing: ${info.title}`);
  20.  
  21.   let data = opts.active.get(message.guild.id) || {};
  22.  
  23.   if(!data.connect) data.connect = await message.member.voiceChannel.join();
  24.   if(!data.queue) data.queue = [];
  25.   data.guildID = message.guild.id;
  26.  
  27.   data.queue.push({
  28.       songTitle: info.title,
  29.       requestedBy: message.author.tag,
  30.       url: args[0],
  31.       announcementChannel: message.channel.id
  32.   });
  33.  
  34.   if(!data.dp) play(bot, opts, data);
  35.   else {
  36.     message.channel.send(`Added To Queue: ${info.title} | Requested By: ${message.author.id}`);
  37.   }
  38.  
  39.   opts.active.set(message.guild.id, data);
  40. };
  41.  
  42. async function play(bot, opts, data) {
  43.     bot.channels.get(data.queue[0].announcementChannel).send(`🎵 Now Playing: ${data.queue[0]} | Requested By: ${data.queue[0].requestedBy}`);
  44.    
  45.     data.dp = await data.connect.playStream(ytdl(data.queue[0].url, { filter: 'audio' }));
  46.     data.dp.guildID = data.guildID;
  47.    
  48.     data.dp.once('finish', function() {
  49.         finish(bot, opts, data)
  50.     });
  51. }
  52.  
  53. function end(bot, opts, dp) {
  54.     let fetched = opts.active.get(dp.guildID)
  55.    
  56.     fetched.queue.shift()
  57.    
  58.    if(fetched.queue.length > 0) {
  59.         opts.active.set(dp.guildID, fetched);
  60.         play(bot, opts, fetched)
  61.    } else {
  62.         opts.active.delete(dp.guildID)
  63.        
  64.         let vc = bot.guilds.get(dp.guildID).me.voiceChannel
  65.         if(vc) vc = vc.leave()
  66.    }
  67. }
  68.  
  69. module.exports.help = {
  70.   name: "play",
  71.   aliases: ["p"]
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement