Advertisement
farfasha

music code

Dec 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. client.on('message', async msg => { // eslint-disable-line
  2.     if (msg.author.bot) return undefined;
  3.     //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  4.     if (!msg.content.startsWith(prefix)) return undefined;
  5.     const args = msg.content.split(' ');
  6.     const searchString = args.slice(1).join(' ');
  7.     //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  8.     const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
  9.     const serverQueue = queue.get(msg.guild.id);
  10. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  11.     let command = msg.content.toLowerCase().split(" ")[0];
  12.     command = command.slice(prefix.length)
  13. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  14.     if (command === `play`) {
  15.         const voiceChannel = msg.member.voiceChannel;
  16.         if (!voiceChannel) return msg.channel.send('يجب توآجد حضرتك بروم صوتي .');
  17.         const permissions = voiceChannel.permissionsFor(msg.client.user);
  18.         if (!permissions.has('CONNECT')) {
  19.             //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  20.             return msg.channel.send('لا يتوآجد لدي صلاحية للتكلم بهذآ الروم');
  21.         }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  22.         if (!permissions.has('SPEAK')) {
  23.             return msg.channel.send('لا يتوآجد لدي صلاحية للتكلم بهذآ الروم');
  24.         }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  25.  
  26.         if (!permissions.has('EMBED_LINKS')) {
  27.             return msg.channel.sendMessage("**يجب توآفر برمشن `EMBED LINKS`لدي **")
  28.         }
  29.  
  30.         if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  31.             const playlist = await youtube.getPlaylist(url);
  32.             const videos = await playlist.getVideos();
  33.             //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  34.             for (const video of Object.values(videos)) {
  35.                 const video2 = await youtube.getVideoByID(video.id); // eslint-disable-line no-await-in-loop
  36.                 await handleVideo(video2, msg, voiceChannel, true); // eslint-disable-line no-await-in-loop
  37.             }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  38.             return msg.channel.send(` **${playlist.title}** تم الإضآفة إلى قأئمة التشغيل`);
  39.         } else {
  40.             try {//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  41.  
  42.                 var video = await youtube.getVideo(url);
  43.             } catch (error) {
  44.                 try {//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  45.                     var videos = await youtube.searchVideos(searchString, 5);
  46.                     let index = 0;
  47.                     const embed1 = new Discord.RichEmbed()
  48.                     .setDescription(`**الرجآء من حضرتك إختيآر رقم المقطع** :
  49. ${videos.map(video2 => `[**${++index} **] \`${video2.title}\``).join('\n')}`)
  50. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  51.                     .setFooter("3bker Community ©")
  52.                     msg.channel.sendEmbed(embed1).then(message =>{message.delete(20000)})
  53.                    
  54.                     // eslint-disable-next-line max-depth
  55.                     try {
  56.                         var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
  57.                             maxMatches: 1,
  58.                             time: 15000,
  59.                             errors: ['time']
  60.                         });//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  61.                     } catch (err) {
  62.                         console.error(err);
  63.                         return msg.channel.send('لم يتم إختيآر مقطع صوتي');
  64.                     }
  65.                     const videoIndex = parseInt(response.first().content);
  66.                     var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
  67.                 } catch (err) {
  68.                     console.error(err);
  69.                     return msg.channel.send(':X: لا يتوفر نتآئج بحث ');
  70.                 }
  71.             }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  72.  
  73.             return handleVideo(video, msg, voiceChannel);
  74.         }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  75.     } else if (command === `skip`) {
  76.         if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  77.         if (!serverQueue) return msg.channel.send('لا يتوفر مقطع لتجآوزه');
  78.         serverQueue.connection.dispatcher.end('تم تجآوز هذآ المقطع');
  79.         return undefined;
  80.     } else if (command === `stop`) {//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  81.         if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  82.         if (!serverQueue) return msg.channel.send('لا يتوفر مقطع لإيقآفه');
  83.         serverQueue.songs = [];
  84.         serverQueue.connection.dispatcher.end('تم إيقآف هذآ المقطع');
  85.         return undefined;
  86.     } else if (command === `vol`) {
  87.         if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  88.         if (!serverQueue) return msg.channel.send('لا يوجد شيء شغآل.');
  89.         if (!args[1]) return msg.channel.send(`:loud_sound: مستوى الصوت **${serverQueue.volume}**`);
  90.         serverQueue.volume = args[1];//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  91.         serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 50);
  92.         return msg.channel.send(`:speaker: تم تغير الصوت الي **${args[1]}**`);
  93.     } else if (command === `np`) {
  94.         if (!serverQueue) return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  95.         const embedNP = new Discord.RichEmbed()
  96.     .setDescription(`:notes: الان يتم تشغيل : **${serverQueue.songs[0].title}**`)
  97.         return msg.channel.sendEmbed(embedNP);
  98.     } else if (command === `queue`) {
  99.         //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  100.         if (!serverQueue) return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  101.         let index = 0;
  102.         //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  103.         const embedqu = new Discord.RichEmbed()
  104. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  105. .setDescription(`**Songs Queue**
  106. ${serverQueue.songs.map(song => `**${++index} -** ${song.title}`).join('\n')}
  107. **الان يتم تشغيل** ${serverQueue.songs[0].title}`)
  108.         return msg.channel.sendEmbed(embedqu);
  109.     } else if (command === `pause`) {
  110.         if (serverQueue && serverQueue.playing) {
  111.             serverQueue.playing = false;
  112.             serverQueue.connection.dispatcher.pause();
  113.             return msg.channel.send('تم إيقاف الموسيقى مؤقتا!');
  114.         }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  115.         return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  116.     } else if (command === "resume") {
  117.         if (serverQueue && !serverQueue.playing) {
  118.             serverQueue.playing = true;
  119.             serverQueue.connection.dispatcher.resume();
  120.             return msg.channel.send('استأنفت الموسيقى بالنسبة لك !');
  121.         }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  122.         return msg.channel.send('لا يوجد شيء حالي في العمل.');
  123.     }
  124.  
  125.     return undefined;
  126. });
  127. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  128. async function handleVideo(video, msg, voiceChannel, playlist = false) {
  129.     const serverQueue = queue.get(msg.guild.id);
  130.     console.log(video);
  131.     //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  132. //  console.log('yao: ' + Util.escapeMarkdown(video.thumbnailUrl));
  133.     const song = {
  134.         id: video.id,
  135.         title: Util.escapeMarkdown(video.title),
  136.         url: `https://www.youtube.com/watch?v=${video.id}`
  137.     };//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  138.     if (!serverQueue) {
  139.         const queueConstruct = {
  140.             textChannel: msg.channel,
  141.             voiceChannel: voiceChannel,
  142.             connection: null,
  143.             songs: [],
  144.             volume: 5,
  145.             playing: true
  146.         };//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  147.         queue.set(msg.guild.id, queueConstruct);
  148. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  149.         queueConstruct.songs.push(song);
  150. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  151.         try {
  152.             var connection = await voiceChannel.join();
  153.             queueConstruct.connection = connection;
  154.             play(msg.guild, queueConstruct.songs[0]);
  155.         } catch (error) {
  156.             console.error(`I could not join the voice channel: ${error}`);
  157.             queue.delete(msg.guild.id);
  158.             return msg.channel.send(`لا أستطيع دخول هذآ الروم ${error}`);
  159.         }
  160.     } else {//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  161.         serverQueue.songs.push(song);
  162.         console.log(serverQueue.songs);
  163.         if (playlist) return undefined;
  164.         else return msg.channel.send(` **${song.title}** تم اضافه الاغنية الي القائمة!`);
  165.     }
  166.     return undefined;
  167. }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  168.  
  169. function play(guild, song) {
  170.     const serverQueue = queue.get(guild.id);
  171.  
  172.     if (!song) {//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  173.         serverQueue.voiceChannel.leave();
  174.         queue.delete(guild.id);
  175.         return;//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  176.     }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  177.     console.log(serverQueue.songs);
  178. //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  179.     const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  180.         .on('end', reason => {//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  181.             if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
  182.             else console.log(reason);
  183.             serverQueue.songs.shift();//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  184.             play(guild, serverQueue.songs[0]);
  185.         })//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  186.         .on('error', error => console.error(error));//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  187.     dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  188.  
  189.     serverQueue.textChannel.send(`بدء تشغيل : **${song.title}**`);
  190. }//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  191.  
  192.  
  193.  
  194. client.on("message", message => {
  195.  if (message.content === `${prefix}`) {
  196.   const embed = new Discord.RichEmbed() //by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  197.       .setColor("#000000")//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  198.       .setDescription(`
  199. ${prefix}play ? لتشغيل أغنية برآبط أو بأسم
  200. ${prefix}skip ? لتجآوز الأغنية الحآلية
  201. ${prefix}pause ? إيقآف الأغنية مؤقتا
  202. ${prefix}resume ? لموآصلة الإغنية بعد إيقآفهآ مؤقتا
  203. ${prefix}vol ? لتغيير درجة الصوت 100 - 0
  204. ${prefix}stop ? لإخرآج البوت من الروم
  205. ${prefix}np ? لمعرفة الأغنية المشغلة حآليا
  206. ${prefix}queue ? لمعرفة قآئمة التشغيل
  207.  `)//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  208.    message.channel.sendEmbed(embed)//by ,$ ReBeL ء , ??#4777 'CODES SERVER'
  209.    
  210.    }
  211.    });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement