Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const colors = require('../colors.json');
- const prefix = "!";
- const ytdl = require('ytdl-core');
- const ffmpeg = require('Ffmpeg');
- module.exports.run = async (bot, message, args, ops) => {
- if(!message.member.voiceChannel) return message.channel.send(`${message.author} You must be in a voice channel for me to connect!`)
- if(!args[0]) return message.channel.send(`${message.author} Please supply a YouTube link.`)
- let validate = await ytdl.validateURL(args[0])
- if(!validate) return message.channel.send(`${message.author} Please supply a valid **YouTube** Link.`)
- let info = await ytdl.getInfo(args[0])
- let data = active.ops.get(message.guild.id) || {};
- if(!data.connection) data.connection = await message.member.voiceChannel.join()
- if(!data.queue) data.queue = []
- data.guildID = message.guild.id
- data.queue.push({
- songTitle: info.title,
- requester: message.author.tag,
- url: args[0],
- announceChannel: message.channel.id
- })
- if(!data.dispatcher) play(bot, ops, data)
- else {
- let embed = new Discord.RichEmbed()
- .setColor(colors.orange)
- .setAuthor(`${message.guild.name} DJ`)
- .setFooter("Bot made by opps 42 for KoLa Servers™", bot.user.displayAvatarURL)
- .setTimestamp()
- .addField(`**Added To Queue:**`, `${info.title}`, true)
- .addField(`**Requested By:**`, `${message.author.tag}`, true)
- message.channel.send(embed)
- }
- active.ops.set(message.guild.id, data)
- }
- async function play(bot, ops, data) {
- bot.channel.get(data.queue[0].announceChannel).send(`Now Playing ${data.queue[0].songTitle} | Requested By: ${data.queue[0].requester} `)
- data.dispatcher = await data.connection.play(ytdl(data.queue[0].url, { filter: `audioonly`}))
- data.dispacther.guildID = data.guildID
- data.dispatcher.once(`finish`, function(){
- finish(bot, ops, this)
- })
- }
- function finish(client, ops, dispatcher) {
- let fetched = active.ops.get(dispacther.guildID)
- fetched.queue.shift()
- if(fetched.queue.length > 0) {
- active.ops.set(dispatcher.guildID, fetched)
- play(bot, ops, fetched)
- } else{
- active.ops.delete(dispatcher.guildID)
- let vc = client.guild.het(dispatcher.guildID).me.voiceChannel
- if(vc) vc.leave()
- }
- }
- module.exports.help = {
- name: "play",
- aliases: ["song", " sr"],
- usage: "!play <youtube link>",
- description: "Use to play songs from youtube!",
- accessibility: "Everyone",
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement