You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

  1. const ytdl = require("ytdl-core");
  2. module.exports = {
  3. name: 'swat',
  4. description: 'SWAT',
  5. roles: ['732345527143759943'],
  6. async execute(message){
  7. const queue = message.client.queue;
  8. const serverQueue = message.client.queue.get(message.guild.id);
  9. const voiceChannel = message.member.voice.channel;
  10. if (!voiceChannel)
  11. return message.channel.send(
  12. "You need to be in a voice channel to SWAT!"
  13. );
  14. if(serverQueue){
  15. while(serverQueue.songs[0]){
  16. serverQueue.songs.shift();
  17. }
  18. serverQueue.songs.push({});
  19. serverQueue.songs.push({title: "SWAT", url: "https://www.youtube.com/watch?v=kNynwelr8ps"});
  20. serverQueue.connection.dispatcher.end();
  21. }else{
  22. const queueContruct = {
  23. textChannel: message.channel,
  24. voiceChannel: voiceChannel,
  25. connection: null,
  26. songs: [],
  27. volume: 5,
  28. playing: true
  29. };
  30. queue.set(message.guild.id, queueContruct);
  31. queueContruct.songs.push({title: "SWAT", url: "https://www.youtube.com/watch?v=kNynwelr8ps"});
  32. try {
  33. var connection = await voiceChannel.join();
  34. queueContruct.connection = connection;
  35. this.play(message, queueContruct.songs[0]);
  36. } catch (err) {
  37. console.log(err);
  38. queue.delete(message.guild.id);
  39. return message.channel.send(err);
  40. }
  41. }
  42. },
  43. play(message, song) {
  44. const queue = message.client.queue;
  45. const guild = message.guild;
  46. const serverQueue = queue.get(message.guild.id);
  47. if (!song) {
  48. serverQueue.voiceChannel.leave();
  49. queue.delete(guild.id);
  50. return;
  51. }
  52. const dispatcher = serverQueue.connection
  53. .play(ytdl(song.url, { filter: 'audioonly', highWaterMark: 1024 * 1024 * 10 }))
  54. .on("finish", () => {
  55. serverQueue.songs.shift();
  56. this.play(message, serverQueue.songs[0]);
  57. })
  58. .on("error", error => console.error(error));
  59. dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  60. serverQueue.textChannel.send(`Start playing: **${song.title}**`);
  61. },
  62. };