SHARE
TWEET

Untitled

BitCodeBot Jul 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const ytdl = require("ytdl-core");
  3. var fs = require('fs'); //FileSystem
  4. let config = JSON.parse(fs.readFileSync("./config.json", "utf8")); // Arq. config
  5.  
  6. exports.run = async (client, message, args, ops) => {
  7.  
  8.   if (config[message.guild.id].djonly == true) {
  9.     if (!message.member.roles.some(r=>config[message.guild.id].djroles.includes(r.id))) return message.channel.send({
  10.       embed: {
  11.         "title": "Erro",
  12.         "description": "Neste servidor, o parametro apenasDJ está ligado\nVocê não tem um cargo de dj, então você não pode tocar musica.\n*Para ver a lista de cargos dj, use `" + config[message.guild.id].prefix + "cargodj`*",
  13.       }
  14.     });
  15.   }
  16.  
  17.   var song = args[0];
  18.   config = JSON.parse(fs.readFileSync("./config.json", "utf8"));
  19.   var streamOptions = {
  20.     seek: 0,
  21.     volume: config[message.guild.id].volume / 100
  22.   };
  23.  
  24.   if (!message.member.voiceChannel) {
  25.     return message.channel.send({
  26.       embed: {
  27.         "title": "Entre em um canal de voz primeiro!",
  28.         "color": 0xff2222
  29.       }
  30.     }).then(msg => {
  31.       if (config[message.guild.id].delete == 'true') {
  32.         msg.delete(config[message.guild.id].deleteTime);
  33.       }
  34.     });
  35.   }
  36.   if (!song) {
  37.     return message.channel.send({
  38.       embed: {
  39.         "title": "Coloque a URl ou Nome de uma música!",
  40.         "color": 0xff2222
  41.       }
  42.     }).then(msg => {
  43.       if (config[message.guild.id].delete == 'true') {
  44.         msg.delete(config[message.guild.id].deleteTime);
  45.       }
  46.     });
  47.   }
  48.  
  49.   let validate = await ytdl.validateURL(song);
  50.  
  51.   if (!validate) {
  52.     let commandFile = require('./pesquisar.js');
  53.     return commandFile.run(client, message, args, ops);
  54.   }
  55.  
  56.   let info = await ytdl.getInfo(song);
  57.   let data = ops.active.get(message.guild.id) || {};
  58.  
  59.   if (!data.connection) {
  60.     data.connection = await message.member.voiceChannel.join();
  61.   }
  62.  
  63.   if (!data.queue) {
  64.     data.queue = [];
  65.   }
  66.  
  67.   data.guildID = message.guild.id;
  68.  
  69.   data.queue.push({
  70.     songTitle: info.title,
  71.     requestAuthor: message.author,
  72.     url: song,
  73.     announceChannel: message.channel.id
  74.   });
  75.  
  76.   if (!data.dispatcher) {
  77.     play(client, ops, data, streamOptions);
  78.   } else {
  79.     message.channel.send(new Discord.RichEmbed()
  80.       .setColor(0x0ea5d3)
  81.       .setAuthor("Sugestão por " + message.author.username, message.author.avatarURL)
  82.       .setDescription("Adicionada a lista **" + info.title + "**")).then(msg => {
  83.       if (config[message.guild.id].delete == 'true') {
  84.         msg.delete(config[message.guild.id].deleteTime);
  85.       }
  86.     });
  87.   }
  88.  
  89.   ops.active.set(message.guild.id, data);
  90.  
  91. }
  92.  
  93. async function play(client, ops, data, streamOptions) {
  94.  
  95.   client.channels.get(data.queue[0].announceChannel).send(new Discord.RichEmbed()
  96.     .setColor(0x0ea5d3)
  97.     .setAuthor("Sugerido por " + data.queue[0].requestAuthor.username, data.queue[0].requestAuthor.avatarURL)
  98.     .setDescription("Tocando agora **" + data.queue[0].songTitle + "**")).then(msg => {
  99.     if (config[data.guildID].delete == 'true') {
  100.       msg.delete(config[data.guildID].deleteTime);
  101.     }
  102.   });
  103.  
  104.   data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].url, {
  105.     filter: "audioonly"
  106.   }), streamOptions);
  107.  
  108.   data.dispatcher.guildID = data.guildID;
  109.  
  110.  data.dispatcher.once('end', function() {
  111.     finish(client, ops, this);
  112.   });
  113.  
  114. }
  115.  
  116. async function finish(client, ops, dispatcher) {
  117.  
  118.   let fetched = ops.active.get(dispatcher.guildID);
  119.   fetched.queue.shift();
  120.  
  121.   if (fetched.queue.length > 0) {
  122.     ops.active.set(dispatcher.guildID, fetched);
  123.     play(client, ops, fetched);
  124.   } else {
  125.     fetched.dispatcher.end();
  126.     ops.active.delete(dispatcher.guildID);
  127.     let vc = client.guilds.get(dispatcher.guildID).me.voiceChannel;
  128.    if (vc) {
  129.       vc.leave();
  130.     }
  131.   }
  132.  
  133. }
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