Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client.handleVideo = async (video, message, vc, playlist = false) => {
- let queue = client.queue.get(message.guild.id);
- let music = {
- id: video.id,
- title: video.title,
- url: `https://www.youtube.com/watch?v=${video.id}`
- };
- if (!queue) {
- let queueConstruct = {
- textChannel: message.channel,
- voiceChannel: vc,
- connection: null,
- musics: [],
- volume: 50,
- playing: true
- };
- let voteConstruct = {
- votes: 0,
- voters: []
- };
- client.queue.set(message.guild.id, queueConstruct);
- client.votes.set(message.guild.id, voteConstruct)
- queueConstruct.musics.push(music);
- try {
- var connection = await vc.join();
- queueConstruct.connection = connection;
- client.play(message.guild, queueConstruct.musics[0]);
- } catch (err) {
- client.queue.delete(message.guild.id);
- console.error(`I could not join your voice channel: ${err}`);
- }
- } else {
- const musicaplaylist = new Discord.RichEmbed()
- .setColor('RANDOM')
- .setDescription(`🎵 **${music.title}** foi adicionada na fila.`);
- queue.musics.push(music);
- if (playlist) return;
- else return message.channel.send(musicaplaylist);
- }
- return;
- }
- client.play = (guild, music) => {
- let queue = client.queue.get(guild.id);
- let votes = client.votes.get(guild.id)
- if (!music) {
- queue.voiceChannel.leave();
- client.queue.delete(guild.id);
- client.votes.delete(guild.id);
- const musicafinalizada = new Discord.RichEmbed()
- .setColor('RANDOM')
- .setDescription('🎵 A musica acabou :)\n Que tal tocar outra?');
- return queue.textChannel.send(musicafinalizada);
- }
- let dispatcher = queue.connection.playStream(ytdl(music.url))
- .on('end', () => {
- queue.musics.shift();
- votes.votes = 0;
- votes.voters = [];
- setTimeout(() => {
- client.play(guild, queue.musics[0]);
- }, 250);
- })
- .on('error', err => console.error(err));
- dispatcher.setVolumeLogarithmic(queue.volume / 100);
- const musicatocando = new Discord.RichEmbed()
- .setColor('RANDOM')
- .setDescription(`🎵 **${music.title}** está tocando agora.`);
- queue.textChannel.send(musicatocando);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement