Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ytdl = require('ytdl-core');
- async function play(bot, ops, data){
- bot.channels.get(data.queue[0].message_channel).send(`Now Playing ${data.queue[0].songTitle} requested by ${data.queue[0].requester}}`)
- data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].song, { filter: 'audioonly' }));
- data.dispatcher.guildID = data.guildID;
- data.dispatcher.once('end', function(){
- finish(bot, ops, this);
- })
- }
- function finish(bot, ops, dispatcher){
- let fetched = ops.queue.get(dispatcher.guildID);
- fetched.queue.shift();
- if(fetched.queue.length > 0){
- ops.queue.set(dispatcher.guildID, fetched)
- play(bot, ops, fetched)
- }
- else {
- ops.queue.delete(dispatcher.guildID);
- let vc = bot.guilds.get(dispatcher.guildID).me.voiceChannel;
- if (vc) {vc.leave()}
- }
- }
- module.exports.run = async (bot, message, args, ops) => {
- try {
- if(!message.member.voiceChannel){return(message.channel.send('ERROR: You need to be connected to a voice channel!'));}
- if(!args[0]){return(message.channel.send('ERROR Please Enter a song/video you want to play.'));}
- let validate = await ytdl.validateURL(args[0]);
- if(!validate){
- let commandFile = require('./search.js')
- return(commandFile.run(bot,message,args,ops))
- }
- let info = await ytdl.getInfo(args[0])
- let data = ops.queue.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,
- song: args[0],
- message_channel: message.channel.id
- });
- if(!data.dispatcher){
- play(bot, ops, data)
- message.guild.me.setMute(false).catch(() => {});
- message.guild.me.setDeaf(true).catch(() => {});
- }
- else{
- message.channel.send(`Added to queue: ${info.title}`)
- }
- ops.queue.set(message.guild.id, data)
- }
- catch (err) {
- console.log(err);
- return(message.channel.send('ERROR: AN unexpected error has occured please contact a developer'))
- }
- }
- module.exports.help = {
- name: "play",
- description: "Usage: Plays Music. Command: <prefix>play <URL or Search Query>"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement