Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const ytdl = require("ytdl-core");
  2. const Discord = require('discord.js');
  3.  
  4. exports.run = async (client, message, args) => {
  5.      
  6.       const link = message.content.split(" ");
  7.       const queue = message.client.queue;
  8.       const serverQueue = message.client.queue.get(message.channel.guild.id)
  9.      
  10.            const voiceChannel = message.member.voiceChannel;
  11.       if (!voiceChannel)
  12.         return message.channel.send("**Entre em um canal de voz. Depois é só me chamar!**");
  13.  
  14.       const permissions = voiceChannel.permissionsFor(message.client.user);
  15.       if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
  16.         return message.channel.send("**Eu não tenho permissão pra soltar a música!**");
  17.       }
  18.  
  19.       const songInfo = await ytdl.getInfo(args[1]);
  20.      
  21.       const song = {
  22.         title: songInfo.title,
  23.         url: songInfo.video_url
  24.       };
  25.  
  26.       if (!serverQueue) {
  27.         const queueContruct = {
  28.           textChannel: message.channel,
  29.           voiceChannel: voiceChannel,
  30.           connection: null,
  31.           songs: [],
  32.           volume: 5,
  33.           playing: true
  34.         }
  35.      
  36.     queue.set(message.guild.id, queueContruct);
  37.     queueContruct.songs.push(song);
  38.  
  39.     try {
  40.         var connection = await voiceChannel.join();
  41.         queueContruct.connection = connection;
  42.         this.play(message, queueContruct.songs[0]);
  43.         message.channel.send(`Estou tocando: ${song.title}`)
  44.    
  45.     } catch (err) {
  46.  
  47.         console.log(err);
  48.         queue.delete(message.guild.id);
  49.         return message.channel.send(err);
  50.        
  51.     } else {
  52.         serverQueue.songs.push(song);
  53.         return message.channel.send(`**${song.title} foi adicionada a playlist!**`);
  54.     }
  55.     } catch (error) {
  56.         message.channel.send("**Apenas link's do youtube serão aceitos**");
  57.     }
  58. }
  59.     play(message, song)
  60.  
  61.     const queue = message.client.queue;
  62.     const guild = message.guild;
  63.     const serverQueue = queue.get(message.guild.id);
  64.  
  65.     const dispatcher = serverQueue.connection
  66.       .playStream(ytdl(song.url, { fliter: "audioonly" }))
  67.       .on("end", () => {
  68.  
  69.         message.channel.send('**Acabou a música!** 🔴');
  70.        
  71.         serverQueue.songs.shift();
  72.         this.play(message, serverQueue.songs[0]);
  73.       })
  74.       .on("error", error => {
  75.         console.error(error);
  76.       });
  77.  
  78.       dispatcher.setVolumeLogarithmic(serverQueue.volume / 10);
  79.  
  80.     exports.help = {
  81.     name: 'play'
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement