Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js')
- const utils = require('../Global/utils');
- const config = require('../Informations/info.json');
- module.exports.run = async (bot, message, args) => {
- let VC = message.member.voiceChannel;
- if (!VC) return message.channel.send(`${message.author.username}, please join a voice channel!`);
- let url = args[0] ? args[0].replace(/<(.+)>/g, '$1') : '';
- let pl = /^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/
- let searchString = args.join(' ');
- if (!url || !searchString) return message.channel.send(`${message.author.username}, please enter a music name or url!`);
- let perms = VC.permissionsFor(message.client.user);
- if (!perms.has('CONNECT')) return message.channel.send(`${message.author}, I do not have permissions to connect to voice channels!`);
- if (!perms.has('SPEAK')) return message.channel.send(`${message.author}, I do not have permissions to speak in a voice channel`);
- if (url.match(pl)) {
- let playlist = await bot.youtube.getPlaylist(url);
- let videos = await playlist.getVideos();
- for (const vid of Object.values(videos)) {
- let video = await bot.youtube.getVideoByID(vid.id)
- await bot.handleVideo(video, message, VC, true)
- }
- return message.channel.send(`🎵 **${playlist.title}** has been added to queue.`);
- } else {
- try {
- var video = await bot.youtube.getVideo(url);
- } catch (err) {
- if (err) undefined;
- try {
- var vid = await bot.youtube.searchVideos(searchString, 1);
- var video = await bot.youtube.getVideoByID(vid[0].id);
- } catch (err) {
- return message.channel.send(`${message.author}, no videos can be found with the argument - \`${searchString}\``);
- }
- }
- return bot.handleVideo(video, message, VC);
- }
- };
- module.exports.help = {
- name: 'play',
- aliases: ['p']
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement