Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. const Discord = require('discord.js')
  2. const utils = require('../Global/utils');
  3. const config = require('../Informations/info.json');
  4.  
  5. module.exports.run = async (bot, message, args) => {
  6.  
  7. let VC = message.member.voiceChannel;
  8. if (!VC) return message.channel.send(`${message.author.username}, please join a voice channel!`);
  9.  
  10. let url = args[0] ? args[0].replace(/<(.+)>/g, '$1') : '';
  11. let pl = /^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/
  12.  
  13. let searchString = args.join(' ');
  14. if (!url || !searchString) return message.channel.send(`${message.author.username}, please enter a music name or url!`);
  15.  
  16. let perms = VC.permissionsFor(message.client.user);
  17. if (!perms.has('CONNECT')) return message.channel.send(`${message.author}, I do not have permissions to connect to voice channels!`);
  18. if (!perms.has('SPEAK')) return message.channel.send(`${message.author}, I do not have permissions to speak in a voice channel`);
  19.  
  20. if (url.match(pl)) {
  21. let playlist = await bot.youtube.getPlaylist(url);
  22. let videos = await playlist.getVideos();
  23.  
  24. for (const vid of Object.values(videos)) {
  25. let video = await bot.youtube.getVideoByID(vid.id)
  26. await bot.handleVideo(video, message, VC, true)
  27. }
  28.  
  29. return message.channel.send(`🎵 **${playlist.title}** has been added to queue.`);
  30. } else {
  31.  
  32. try {
  33. var video = await bot.youtube.getVideo(url);
  34. } catch (err) {
  35. if (err) undefined;
  36. try {
  37. var vid = await bot.youtube.searchVideos(searchString, 1);
  38. var video = await bot.youtube.getVideoByID(vid[0].id);
  39. } catch (err) {
  40. return message.channel.send(`${message.author}, no videos can be found with the argument - \`${searchString}\``);
  41. }
  42. }
  43. return bot.handleVideo(video, message, VC);
  44. }
  45. };
  46.  
  47. module.exports.help = {
  48. name: 'play',
  49. aliases: ['p']
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement