SHARE
TWEET

Untitled

a guest Jul 19th, 2019 45 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, ops) => {
  5.  
  6.     if (!message.member.voiceChannel) return message.channel.send('```Me desculpe, mas você precisa estar em um canal de voz para tocar a música!```')
  7.    
  8.     if (!args[0]) return message.channel.send('```Coloque o link da música ou digite o nome.```');
  9.  
  10.     let validate = await ytdl.validateURL(args[0]);
  11.  
  12.     if (!validate) {
  13.         let commandFile = require(`./search.js`);
  14.         return commandFile.run(client, message, args, ops);
  15.     }
  16.    
  17.    let info = await ytdl.getInfo(args[0]);
  18.  
  19.    let data = ops.active.get(message.guild.id) || {};
  20.  
  21.    if (!data.connection) data.connection = await message.member.voiceChannel.join();
  22.    if (!data.queue) data.queue = [];
  23.    data.guildID = message.guild.id;
  24.  
  25.    data.queue.push({
  26.        songTitle: info.title,
  27.        requester: message.author.id,
  28.        url: args[0],
  29.        announceChannel: message.channel.id
  30.    });
  31.  
  32.    if (!data.dispatcher) play(client, ops, data);
  33.    else {
  34.  
  35.     let queueembed = new discord.RichEmbed()
  36.     .setColor('RANDOM')
  37.     .setTitle("<a:play:576898572155355169>")
  38.     .setDescription(`**A música: ${info.title} foi adicionada a lista. | Requisitada por: <@${message.author.id}>**`)
  39.     message.channel.send(queueembed)
  40.    }
  41.  
  42.    ops.active.set(message.guild.id, data);
  43. }
  44.  
  45. async function play(client, ops, data) {
  46.     let playembed = new discord.RichEmbed()
  47.     .setColor('RANDOM')
  48.     .setTitle("<a:play:576898572155355169>")
  49.     .setDescription(`**Começando a tocar: ${data.queue[0].songTitle} | Requisitada por: <@${data.queue[0].requester}>**`);
  50.    
  51.     client.channels.get(data.queue[0].announceChannel).send(playembed)
  52.  
  53.     data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].url, { filter: 'audioonly'}));
  54.     data.dispatcher.guildID = data.guildID;
  55.  
  56.     data.dispatcher.once('finish', function() {
  57.        
  58.         finish(client, ops, this);
  59.     });
  60. }
  61.  
  62.  
  63.  
  64. function finish(client, ops, dispatcher) {
  65.  
  66.     let fetched = ops.active.get(dispatcher.guildID);
  67.  
  68.     fetched.queue.shift();
  69.  
  70.     if (fetched.queue.lenght > 0) {
  71.  
  72.         ops.active.set(dispatcher.guildID, fetched);
  73.  
  74.         play(client, ops, fetched)
  75.  
  76.     } else {
  77.  
  78.         ops.active.delete(dispatcher.guildID);
  79.  
  80.         let vc = client.guilds.get(dispatcher.guildID).me.voiceChannel;
  81.         if (vc) vc.leave();
  82.     }
  83.  
  84.  
  85. }
  86.  
  87. module.exports.help = {
  88.      name: "play"
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top