Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (message.content.startsWith(`${perfix}play`)) {
  2.     execute(message, serverQueue);
  3.     return;
  4.   } else if (message.content.startsWith(`${perfix}skip`)) {
  5.     skip(message, serverQueue);
  6.     return;
  7.   } else if (message.content.startsWith(`${perfix}stop`)) {
  8.     stop(message, serverQueue);
  9.     return;
  10.   } else {
  11.  
  12.    return;
  13.   }
  14. });
  15.  
  16.  
  17. async function execute(message, serverQueue) {
  18.   const args = message.content.split(" ");
  19.   const voiceChannel = message.member.voiceChannel;
  20.   if (!voiceChannel) {
  21.  
  22.   }
  23.   const permissions = voiceChannel.permissionsFor(message.client.user);
  24.   if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
  25.  
  26.   }
  27.   const songInfo = await ytdl.getInfo(args[1]);
  28.   const song = {
  29.     title: songInfo.title,
  30.     url: songInfo.video_url
  31.   };
  32.   if (!serverQueue) {
  33.     const queueContruct = {
  34.       textChannel: message.channel,
  35.       voiceChannel: voiceChannel,
  36.       connection: null,
  37.       songs: [],
  38.       volume: 5,
  39.       playing: true
  40.     };
  41.     queue.set(message.guild.id, queueContruct);
  42.     queueContruct.songs.push(song);
  43.     try {
  44.       var connection = await voiceChannel.join();
  45.       queueContruct.connection = connection;
  46.       play(message.guild, queueContruct.songs[0]);
  47.     } catch (err) {
  48.       console.log(err);
  49.       queue.delete(message.guild.id);
  50.       return message.channel.send(err);
  51.     }
  52.   } else {
  53.     serverQueue.songs.push(song);
  54.     console.log(serverQueue.songs);
  55.  
  56.   }
  57. }
  58. async function skip(message, serverQueue) {
  59.   if (!message.member.voiceChannel) {
  60.  
  61.  
  62.   }
  63.   if (!serverQueue) {
  64.   }
  65.   serverQueue.connection.dispatcher.end();
  66. }
  67. async function stop(message, serverQueue) {
  68.   if (!message.member.voiceChannel) {
  69.   }
  70.   serverQueue.songs = [];
  71.   serverQueue.connection.dispatcher.end();
  72. }
  73. function play(guild, song) {
  74.   const serverQueue = queue.get(guild.id);
  75.   if (!song) {
  76.     serverQueue.voiceChannel.leave();
  77.     queue.delete(guild.id);
  78.     return;
  79.   }
  80.   const dispatcher = serverQueue.connection
  81.     .playStream(ytdl(song.url))
  82.     .on("end", () => {
  83.       console.log("Music ended!");
  84.       serverQueue.songs.shift();
  85.       play(guild, serverQueue.songs[0]);
  86.     })
  87.     .on("error", error => {
  88.       console.error(error);
  89.     });
  90.   dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement