Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. client.handleVideo = async (video, message, vc, playlist = false) => {
  2. let queue = client.queue.get(message.guild.id);
  3. let music = {
  4. id: video.id,
  5. title: video.title,
  6. url: `https://www.youtube.com/watch?v=${video.id}`
  7. };
  8.  
  9. if (!queue) {
  10. let queueConstruct = {
  11. textChannel: message.channel,
  12. voiceChannel: vc,
  13. connection: null,
  14. musics: [],
  15. volume: 50,
  16. playing: true
  17. };
  18. let voteConstruct = {
  19. votes: 0,
  20. voters: []
  21. };
  22.  
  23. client.queue.set(message.guild.id, queueConstruct);
  24. client.votes.set(message.guild.id, voteConstruct)
  25. queueConstruct.musics.push(music);
  26.  
  27. try {
  28. var connection = await vc.join();
  29. queueConstruct.connection = connection;
  30. client.play(message.guild, queueConstruct.musics[0]);
  31. } catch (err) {
  32. client.queue.delete(message.guild.id);
  33. console.error(`I could not join your voice channel: ${err}`);
  34. }
  35. } else {
  36. const musicaplaylist = new Discord.RichEmbed()
  37. .setColor('RANDOM')
  38. .setDescription(`🎵 **${music.title}** foi adicionada na fila.`);
  39.  
  40. queue.musics.push(music);
  41. if (playlist) return;
  42. else return message.channel.send(musicaplaylist);
  43. }
  44. return;
  45. }
  46.  
  47. client.play = (guild, music) => {
  48. let queue = client.queue.get(guild.id);
  49. let votes = client.votes.get(guild.id)
  50. if (!music) {
  51. queue.voiceChannel.leave();
  52. client.queue.delete(guild.id);
  53. client.votes.delete(guild.id);
  54. const musicafinalizada = new Discord.RichEmbed()
  55.  
  56. .setColor('RANDOM')
  57. .setDescription('🎵 A musica acabou :)\n Que tal tocar outra?');
  58. return queue.textChannel.send(musicafinalizada);
  59. }
  60.  
  61. let dispatcher = queue.connection.playStream(ytdl(music.url))
  62. .on('end', () => {
  63. queue.musics.shift();
  64. votes.votes = 0;
  65. votes.voters = [];
  66. setTimeout(() => {
  67. client.play(guild, queue.musics[0]);
  68. }, 250);
  69. })
  70. .on('error', err => console.error(err));
  71. dispatcher.setVolumeLogarithmic(queue.volume / 100);
  72.  
  73. const musicatocando = new Discord.RichEmbed()
  74.  
  75. .setColor('RANDOM')
  76. .setDescription(`🎵 **${music.title}** está tocando agora.`);
  77.  
  78. queue.textChannel.send(musicatocando);
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement