Advertisement
opps_42

play.js

Nov 19th, 2019
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const colors = require('../colors.json');
  3. const prefix = "!";
  4. const ytdl = require('ytdl-core');
  5. const ffmpeg = require('Ffmpeg');
  6.  
  7. module.exports.run = async (bot, message, args, ops) => {
  8. if(!message.member.voiceChannel) return message.channel.send(`${message.author} You must be in a voice channel for me to connect!`)
  9.  
  10.  
  11.  
  12. if(!args[0]) return message.channel.send(`${message.author} Please supply a YouTube link.`)
  13.  
  14. let validate = await ytdl.validateURL(args[0])
  15.  
  16. if(!validate) return message.channel.send(`${message.author} Please supply a valid **YouTube** Link.`)
  17.  
  18. let info = await ytdl.getInfo(args[0])
  19.  
  20. let data = active.ops.get(message.guild.id) || {};
  21.  
  22. if(!data.connection) data.connection = await message.member.voiceChannel.join()
  23. if(!data.queue) data.queue = []
  24. data.guildID = message.guild.id
  25.  
  26. data.queue.push({
  27. songTitle: info.title,
  28. requester: message.author.tag,
  29. url: args[0],
  30. announceChannel: message.channel.id
  31. })
  32.  
  33. if(!data.dispatcher) play(bot, ops, data)
  34. else {
  35. let embed = new Discord.RichEmbed()
  36. .setColor(colors.orange)
  37. .setAuthor(`${message.guild.name} DJ`)
  38. .setFooter("Bot made by opps 42 for KoLa Servers™", bot.user.displayAvatarURL)
  39. .setTimestamp()
  40. .addField(`**Added To Queue:**`, `${info.title}`, true)
  41. .addField(`**Requested By:**`, `${message.author.tag}`, true)
  42.  
  43. message.channel.send(embed)
  44. }
  45. active.ops.set(message.guild.id, data)
  46.  
  47. }
  48.  
  49. async function play(bot, ops, data) {
  50. bot.channel.get(data.queue[0].announceChannel).send(`Now Playing ${data.queue[0].songTitle} | Requested By: ${data.queue[0].requester} `)
  51.  
  52. data.dispatcher = await data.connection.play(ytdl(data.queue[0].url, { filter: `audioonly`}))
  53. data.dispacther.guildID = data.guildID
  54.  
  55. data.dispatcher.once(`finish`, function(){
  56. finish(bot, ops, this)
  57. })
  58. }
  59.  
  60. function finish(client, ops, dispatcher) {
  61. let fetched = active.ops.get(dispacther.guildID)
  62.  
  63. fetched.queue.shift()
  64.  
  65. if(fetched.queue.length > 0) {
  66. active.ops.set(dispatcher.guildID, fetched)
  67.  
  68. play(bot, ops, fetched)
  69. } else{
  70. active.ops.delete(dispatcher.guildID)
  71.  
  72. let vc = client.guild.het(dispatcher.guildID).me.voiceChannel
  73. if(vc) vc.leave()
  74. }
  75. }
  76. module.exports.help = {
  77. name: "play",
  78. aliases: ["song", " sr"],
  79. usage: "!play <youtube link>",
  80. description: "Use to play songs from youtube!",
  81. accessibility: "Everyone",
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement