Advertisement
Guest User

Untitled

a guest
May 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. const ytdl = require('ytdl-core');
  2. exports.run = async (client, message, args, ops) => {
  3. if (!message.member.voiceChannel) return message.channel.send('Entrez dans un canal audio !');
  4. if (message.guild.me.voiceChannel) return message.channel.send('Désolé, le bot est déjà occuper autre part. (¬‿¬ )');
  5. if (!args[0]) return message.channel.send('Désolé, veuillez entrez une URL pour executer cette commande.');
  6.  
  7. let validate = await ytdl.validateURL(args[0]);
  8. if (!validate) return message.channel.send('Désolé, veuillez entrez une URL **correcte** pour executer cette commande.');
  9.  
  10. let info = await ytdl.getInfo(args[0]);
  11.  
  12. let data = ops.active.get(message.guild.id) || {};
  13.  
  14. if (!data.connection) data.connection = await message.member.voiceChannel.join();
  15. if (!data.queue) data.queue = [];
  16.  
  17. data.guildID = message.guild.id;
  18.  
  19. data.queue.push({
  20. songTitle: info.title,
  21. requester: message.author.tag,
  22. url: args[0],
  23. announceChannel: message.channel.id
  24. });
  25.  
  26. if (!data.dispatcher) play(client, ops, data);
  27. else {
  28. message.channel.send(`Ajouter à la file d'attente : ${info.title} | Demander par : ${message.author.id}`);
  29. }
  30.  
  31. ops.active.set(message.guild.id, data);
  32. }
  33.  
  34. async function play(client, ops, data) {
  35. client.channels.get(data.queue[0].announceChannel).send(`Lecture en cours : ${data.queue[0].songTitle} | Demander par ${data.queue.requester}`);
  36.  
  37. data.dispatcher = await data.connection.play(ytdl(data.queue[0].url, { filter : 'audioonly' }));
  38. data.dispatcher.guildID = data.guildID;
  39. data.dispatcher.once('finish',function() {
  40. finish(client, ops, this);
  41. });
  42. }
  43.  
  44. function finish(client, ops, dispatcher) {
  45. let fetched = ops.active.get(dispatcher.guildID);
  46. fetched.queue.shift();
  47. if (fetched.queue.length > 0) {
  48. ops.active.set(dispatcher.guildID, fetched);
  49. play(client, ops, fetched);
  50. } else {
  51. ops.active.delete(dispatcher.guildID);
  52.  
  53. let vc = client.guilds.get(dispatcher.guildID).me.voiceChannel;
  54. if (vc) vc.leave();
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement