SHARE
TWEET

كود ميوزك مطور

discord-Ahmed Feb 27th, 2020 (edited) 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. client.on("message", async message => {
  2.   var args = message.content.substring(prefix.length).split(" ");
  3.   if (!message.content.startsWith(prefix)) return;
  4.   var searchString = args.slice(1).join(" ");
  5.   var url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
  6.   var serverQueue = queue.get(message.guild.id);
  7.   switch (args[0].toLowerCase()) {
  8.     case "play":
  9.       var voiceChannel = message.member.voiceChannel;
  10.       if (!voiceChannel)
  11.         return message.channel.send(
  12.           "I'm sorry but you need to be in a voice channel to play music!"
  13.         );
  14.       var permissions = voiceChannel.permissionsFor(message.client.user);
  15.       if (!permissions.has("CONNECT")) {
  16.         return message.channel.send(
  17.           "I cannot connect to your voice channel, make sure I have the proper permissions!"
  18.         );
  19.       }
  20.       if (!permissions.has("SPEAK")) {
  21.         return message.channel.send(
  22.           "I cannot speak in this voice channel, make sure I have the proper permissions!"
  23.         );
  24.       }
  25.       if (
  26.         url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)
  27.       ) {
  28.         var playlist = await youtube.getPlaylist(url);
  29.         var videos = await playlist.getVideos();
  30.         for (const video of Object.values(videos)) {
  31.           var video2 = await youtube.getVideoByID(video.id); // eslint-disable-line no-await-in-loop
  32.           await handleVideo(video2, message, voiceChannel, true); // eslint-disable-line no-await-in-loop
  33.         }
  34.         return message.channel.send(
  35.           `✅ Playlist: **${playlist.title}** has been added to the queue!`
  36.         );
  37.       } else {
  38.         try {
  39.           var video = await youtube.getVideo(url);
  40.         } catch (error) {
  41.           try {
  42.             var videos = await youtube.searchVideos(searchString, 10);
  43.             var index = 0;
  44.             message.channel.send(`
  45. __**Song selection:**__
  46. ${videos.map(video2 => `**${++index} -** ${video2.title}`).join("n")}
  47. Please provide a value to select one of the search results ranging from 1-10.
  48.                     `);
  49.             // eslint-disable-next-line max-depth
  50.             try {
  51.               var response = await message.channel.awaitMessages(
  52.                 message2 => message2.content > 0 && message2.content < 11,
  53.                 {
  54.                   maxMatches: 1,
  55.                   time: 10000,
  56.                   errors: ["time"]
  57.                 }
  58.               );
  59.             } catch (err) {
  60.               console.error(err);
  61.               return message.channel.send(
  62.                 "No or invalid value entered, cancelling video selection."
  63.               );
  64.             }
  65.             var videoIndex = parseInt(response.first().content);
  66.             var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
  67.           } catch (err) {
  68.             console.error(err);
  69.             return message.channel.send(
  70.               "🆘 I could not obtain any search results."
  71.             );
  72.           }
  73.         }
  74.         return handleVideo(video, message, voiceChannel);
  75.       }
  76.       break;
  77.     case "skip":
  78.       if (!message.member.voiceChannel)
  79.         return message.channel.send("You are not in a voice channel!");
  80.       if (!serverQueue)
  81.         return message.channel.send(
  82.           "There is nothing playing that I could skip for you."
  83.         );
  84.       serverQueue.connection.dispatcher.end("Skip command has been used!");
  85.       return undefined;
  86.       break;
  87.     case "stop":
  88.       if (!message.member.voiceChannel)
  89.         return message.channel.send("You are not in a voice channel!");
  90.       if (!serverQueue)
  91.         return message.channel.send(
  92.           "There is nothing playing that I could stop for you."
  93.         );
  94.       serverQueue.songs = [];
  95.       serverQueue.connection.dispatcher.end("Stop command has been used!");
  96.       return undefined;
  97.       break;
  98.     case "volume":
  99.       if (!message.member.voiceChannel)
  100.         return message.channel.send("You are not in a voice channel!");
  101.       if (!serverQueue)
  102.         return message.channel.send("There is nothing playing.");
  103.       if (!args[1])
  104.         return message.channel.send(
  105.           `The current volume is: **${serverQueue.volume}**`
  106.         );
  107.       serverQueue.volume = args[1];
  108.       serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 5);
  109.       return message.channel.send(`I set the volume to: **${args[1]}**`);
  110.       break;
  111.     case "np":
  112.       if (!serverQueue)
  113.         return message.channel.send("There is nothing playing.");
  114.       return message.channel.send(
  115.         `🎶 Now playing: **${serverQueue.songs[0].title}**`
  116.       );
  117.       break;
  118.     case "queue":
  119.       if (!serverQueue)
  120.         return message.channel.send("There is nothing playing.");
  121.       return message.channel.send(`
  122. __**Song queue:**__
  123. ${serverQueue.songs.map(song => `**-** ${song.title}`).join("n")}
  124. **Now playing:** ${serverQueue.songs[0].title}
  125.         `);
  126.       break;
  127.     case "pause":
  128.       if (serverQueue && serverQueue.playing) {
  129.         serverQueue.playing = false;
  130.         serverQueue.connection.dispatcher.pause();
  131.         return message.channel.send("⏸ Paused the music for you!");
  132.       }
  133.       return message.channel.send("There is nothing playing.");
  134.       break;
  135.     case "resume":
  136.       if (serverQueue && !serverQueue.playing) {
  137.         serverQueue.playing = true;
  138.         serverQueue.connection.dispatcher.resume();
  139.         return message.channel.send("▶ Resumed the music for you!");
  140.       }
  141.       return message.channel.send("There is nothing playing.");
  142.  
  143.       return undefined;
  144.       break;
  145.   }
  146.   async function handleVideo(video, message, voiceChannel, playlist = false) {
  147.     var serverQueue = queue.get(message.guild.id);
  148.     console.log(video);
  149.     var song = {
  150.       id: video.id,
  151.       title: video.title,
  152.       url: `https://www.youtube.com/watch?v=${video.id}`
  153.     };
  154.     if (!serverQueue) {
  155.       var queueConstruct = {
  156.         textChannel: message.channel,
  157.         voiceChannel: voiceChannel,
  158.         connection: null,
  159.         songs: [],
  160.         volume: 5,
  161.         playing: true
  162.       };
  163.       queue.set(message.guild.id, queueConstruct);
  164.  
  165.       queueConstruct.songs.push(song);
  166.  
  167.       try {
  168.         var connection = await voiceChannel.join();
  169.         queueConstruct.connection = connection;
  170.         play(message.guild, queueConstruct.songs[0]);
  171.       } catch (error) {
  172.         console.error(`I could not join the voice channel: ${error}`);
  173.         queue.delete(message.guild.id);
  174.         return message.channel.send(
  175.           `I could not join the voice channel: ${error}`
  176.         );
  177.       }
  178.     } else {
  179.       serverQueue.songs.push(song);
  180.       console.log(serverQueue.songs);
  181.       if (playlist) return undefined;
  182.       else
  183.         return message.channel.send(
  184.           `✅ **${song.title}** has been added to the queue!`
  185.         );
  186.     }
  187.     return undefined;
  188.   }
  189.   function play(guild, song) {
  190.     var serverQueue = queue.get(guild.id);
  191.  
  192.     if (!song) {
  193.       serverQueue.voiceChannel.leave();
  194.       queue.delete(guild.id);
  195.       return;
  196.     }
  197.     console.log(serverQueue.songs);
  198.  
  199.     const dispatcher = serverQueue.connection
  200.       .playStream(ytdl(song.url))
  201.       .on("end", reason => {
  202.         message.channel.send("``The queue of song is end.``");
  203.         if (reason === "Stream is not generating quickly enough.")
  204.           console.log("Song ended.");
  205.         else console.log(reason);
  206.         serverQueue.songs.shift();
  207.         play(guild, serverQueue.songs[0]);
  208.       })
  209.       .on("error", error => console.error(error));
  210.     dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  211.  
  212.     serverQueue.textChannel.send(`🎶 Start playing: **${song.title}**`); //${! .₳Ⱨ₥ɆĐ ♡}#0561
  213.   }
  214. });//𝕊𝓝Ỗ𝔀𝓎© copyRight 2020
  215. //${! .₳Ⱨ₥ɆĐ ♡}#0561
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