Advertisement
Guest User

كود الميوزك

a guest
Jul 23rd, 2018
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.99 KB | None | 0 0
  1.  
  2. const Discord = require('discord.js');
  3.  
  4. const client = new Discord.Client();
  5.  
  6. const prefix = "=";
  7.  
  8. client.on('ready', () => {
  9.  
  10. console.log('I am ready!');
  11.  
  12. });
  13.  
  14. client.on('message', message => {
  15.  
  16. if (message.content === 'ping') {
  17.  
  18. message.reply('pong');
  19.  
  20. }
  21.  
  22. });
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. const ytdl = require("ytdl-core");
  30. const { Client, Util } = require('discord.js');
  31. const getYoutubeID = require('get-youtube-id');
  32. const fetchVideoInfo = require('youtube-info');
  33. const YouTube = require('simple-youtube-api');
  34. const youtube = new YouTube("AIzaSyAdORXg7UZUo7sePv97JyoDqtQVi3Ll0b8");
  35. const queue = new Map();
  36.  
  37.  
  38. /*
  39. البكجآت
  40. npm install discord.js
  41. npm install ytdl-core
  42. npm install get-youtube-id
  43. npm install youtube-info
  44. npm install simple-youtube-api
  45. npm install queue
  46. */
  47.  
  48. client.on('ready', () => {
  49. console.log(`Logged in as ${client.user.tag}!`);
  50. console.log(`in ${client.guilds.size} servers `)
  51. console.log(`[Thereaper] ${client.users.size}`)
  52. client.user.setStatus("dnd")
  53. });
  54. //by ! - Thereaper'
  55.  
  56. client.on('message', async msg => { // eslint-disable-line
  57. if (msg.author.bot) return undefined;
  58. //by ! - Thereaper'
  59. if (!msg.content.startsWith(prefix)) return undefined;
  60. const args = msg.content.split(' ');
  61. const searchString = args.slice(1).join(' ');
  62. //by ! - Thereaper'
  63. const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
  64. const serverQueue = queue.get(msg.guild.id);
  65. //by ! - Thereaper'
  66. let command = msg.content.toLowerCase().split(" ")[0];
  67. command = command.slice(prefix.length)
  68. //by ! - Thereaper'
  69. if (command === `play`) {
  70. const voiceChannel = msg.member.voiceChannel;
  71. if (!voiceChannel) return msg.channel.send('يجب توآجد حضرتك بروم صوتي .');
  72. const permissions = voiceChannel.permissionsFor(msg.client.user);
  73. if (!permissions.has('CONNECT')) {
  74. //by ! - Thereaper'
  75. return msg.channel.send('لا يتوآجد لدي صلاحية للتكلم بهذآ الروم');
  76. }//by ! - Thereaper'
  77. if (!permissions.has('SPEAK')) {
  78. return msg.channel.send('لا يتوآجد لدي صلاحية للتكلم بهذآ الروم');
  79. }//by ! - Thereaper'
  80.  
  81. if (!permissions.has('EMBED_LINKS')) {
  82. return msg.channel.sendMessage("**يجب توآفر برمشن `EMBED LINKS`لدي **")
  83. }
  84.  
  85. if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  86. const playlist = await youtube.getPlaylist(url);
  87. const videos = await playlist.getVideos();
  88. //by ! - Thereaper'
  89. for (const video of Object.values(videos)) {
  90. const video2 = await youtube.getVideoByID(video.id); // eslint-disable-line no-await-in-loop
  91. await handleVideo(video2, msg, voiceChannel, true); // eslint-disable-line no-await-in-loop
  92. }//by ! - Thereaper'
  93. return msg.channel.send(` **${playlist.title}** تم الإضآفة إلى قأئمة التشغيل`);
  94. } else {
  95. try {//by ! - Thereaper'
  96.  
  97. var video = await youtube.getVideo(url);
  98. } catch (error) {
  99. try {//by ! - Thereaper'
  100. var videos = await youtube.searchVideos(searchString, 5);
  101. let index = 0;
  102. const embed1 = new Discord.RichEmbed()
  103. .setDescription(`**الرجآء من حضرتك إختيآر رقم المقطع** :
  104. ${videos.map(video2 => `[**${++index} **] \`${video2.title}\``).join('\n')}`)
  105. //by ! - Thereaper'
  106. .setFooter("Threaper")
  107. msg.channel.sendEmbed(embed1).then(message =>{message.delete(20000)})
  108.  
  109. // eslint-disable-next-line max-depth
  110. try {
  111. var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
  112. maxMatches: 1,
  113. time: 15000,
  114. errors: ['time']
  115. });//by ! - Thereaper'
  116. } catch (err) {
  117. console.error(err);
  118. return msg.channel.send('لم يتم إختيآر مقطع صوتي');
  119. }
  120. const videoIndex = parseInt(response.first().content);
  121. var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
  122. } catch (err) {
  123. console.error(err);
  124. return msg.channel.send(':X: لا يتوفر نتآئج بحث ');
  125. }
  126. }//by ! - Thereaper'
  127.  
  128. return handleVideo(video, msg, voiceChannel);
  129. }//by ! - Thereaper'
  130. } else if (command === `skip`) {
  131. if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  132. if (!serverQueue) return msg.channel.send('لا يتوفر مقطع لتجآوزه');
  133. serverQueue.connection.dispatcher.end('تم تجآوز هذآ المقطع');
  134. return undefined;
  135. } else if (command === `stop`) {//by ! - Thereaper'
  136. if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  137. if (!serverQueue) return msg.channel.send('لا يتوفر مقطع لإيقآفه');
  138. serverQueue.songs = [];
  139. serverQueue.connection.dispatcher.end('تم إيقآف هذآ المقطع');
  140. return undefined;
  141. } else if (command === `vol`) {
  142. if (!msg.member.voiceChannel) return msg.channel.send('أنت لست بروم صوتي .');
  143. if (!serverQueue) return msg.channel.send('لا يوجد شيء شغآل.');
  144. if (!args[1]) return msg.channel.send(`:loud_sound: مستوى الصوت **${serverQueue.volume}**`);
  145. serverQueue.volume = args[1];//by ! - Thereaper'
  146. serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 50);
  147. return msg.channel.send(`:speaker: تم تغير الصوت الي **${args[1]}**`);
  148. } else if (command === `np`) {
  149. if (!serverQueue) return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  150. const embedNP = new Discord.RichEmbed()
  151. .setDescription(`:notes: الان يتم تشغيل : **${serverQueue.songs[0].title}**`)
  152. return msg.channel.sendEmbed(embedNP);
  153. } else if (command === `queue`) {
  154. //by ! - Thereaper'
  155. if (!serverQueue) return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  156. let index = 0;
  157. //by ! - Thereaper'
  158. const embedqu = new Discord.RichEmbed()
  159. //by ! - Thereaper'
  160. .setDescription(`**Songs Queue**
  161. ${serverQueue.songs.map(song => `**${++index} -** ${song.title}`).join('\n')}
  162. **الان يتم تشغيل** ${serverQueue.songs[0].title}`)
  163. return msg.channel.sendEmbed(embedqu);
  164. } else if (command === `pause`) {
  165. if (serverQueue && serverQueue.playing) {
  166. serverQueue.playing = false;
  167. serverQueue.connection.dispatcher.pause();
  168. return msg.channel.send('تم إيقاف الموسيقى مؤقتا!');
  169. }//by ! - Thereaper'
  170. return msg.channel.send('لا يوجد شيء حالي ف العمل.');
  171. } else if (command === "resume") {
  172. if (serverQueue && !serverQueue.playing) {
  173. serverQueue.playing = true;
  174. serverQueue.connection.dispatcher.resume();
  175. return msg.channel.send('استأنفت الموسيقى بالنسبة لك !');
  176. }//by ! - Thereaper'
  177. return msg.channel.send('لا يوجد شيء حالي في العمل.');
  178. }
  179.  
  180. return undefined;
  181. });
  182. //by ! - Thereaper'
  183. async function handleVideo(video, msg, voiceChannel, playlist = false) {
  184. const serverQueue = queue.get(msg.guild.id);
  185. console.log(video);
  186. //by ! - Thereaper'
  187. // console.log('yao: ' + Util.escapeMarkdown(video.thumbnailUrl));
  188. const song = {
  189. id: video.id,
  190. title: Util.escapeMarkdown(video.title),
  191. url: `https://www.youtube.com/watch?v=${video.id}`
  192. };//by ! - Thereaper'
  193. if (!serverQueue) {
  194. const queueConstruct = {
  195. textChannel: msg.channel,
  196. voiceChannel: voiceChannel,
  197. connection: null,
  198. songs: [],
  199. volume: 5,
  200. playing: true
  201. };//by ! - Thereaper'
  202. queue.set(msg.guild.id, queueConstruct);
  203. //by ! - Thereaper'
  204. queueConstruct.songs.push(song);
  205. //by ! - Thereaper'
  206. try {
  207. var connection = await voiceChannel.join();
  208. queueConstruct.connection = connection;
  209. play(msg.guild, queueConstruct.songs[0]);
  210. } catch (error) {
  211. console.error(`I could not join the voice channel: ${error}`);
  212. queue.delete(msg.guild.id);
  213. return msg.channel.send(`لا أستطيع دخول هذآ الروم ${error}`);
  214. }
  215. } else {//by ! - Thereaper'
  216. serverQueue.songs.push(song);
  217. console.log(serverQueue.songs);
  218. if (playlist) return undefined;
  219. else return msg.channel.send(` **${song.title}** تم اضافه الاغنية الي القائمة!`);
  220. }
  221. return undefined;
  222. }//by ! - Thereaper'
  223.  
  224. function play(guild, song) {
  225. const serverQueue = queue.get(guild.id);
  226.  
  227. if (!song) {//by ! - Thereaper'
  228. serverQueue.voiceChannel.leave();
  229. queue.delete(guild.id);
  230. return;//by ! - Thereaper'
  231. }//by ! - Thereaper'
  232. console.log(serverQueue.songs);
  233. //by ! - Thereaper'
  234. const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  235. .on('end', reason => {//by ! - Thereaper'
  236. if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
  237. else console.log(reason);
  238. serverQueue.songs.shift();//by ! - Thereaper'
  239. play(guild, serverQueue.songs[0]);
  240. })//by ! - Thereaper'
  241. .on('error', error => console.error(error));//by ! - Thereaper'
  242. dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);//by ! - Thereaper'
  243.  
  244. serverQueue.textChannel.send(`بدء تشغيل : **${song.title}**`);
  245. }//by ! - Thereaper'
  246.  
  247.  
  248.  
  249. client.on("message", message => {
  250. if (message.content === `${prefix}help1`) {
  251. const embed = new Discord.RichEmbed() //by ! - Thereaper'
  252. .setColor("#000000")//by ! - Thereaper'
  253. .setDescription(`
  254. ${prefix}play ⇏ لتشغيل أغنية برآبط أو بأسم
  255. ${prefix}skip ⇏ لتجآوز الأغنية الحآلية
  256. ${prefix}pause ⇏ إيقآف الأغنية مؤقتا
  257. ${prefix}resume ⇏ لموآصلة الإغنية بعد إيقآفهآ مؤقتا
  258. ${prefix}vol ⇏ لتغيير درجة الصوت 100 - 0
  259. ${prefix}stop ⇏ لإخرآج البوت من الروم
  260. ${prefix}np ⇏ لمعرفة الأغنية المشغلة حآليا
  261. ${prefix}queue ⇏ لمعرفة قآئمة التشغيل
  262. `)//by ! - Thereaper'
  263. message.channel.sendEmbed(embed)//by ! - Thereaper'
  264.  
  265. }
  266. });
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282. client.login(process.env.BOT_TOKEN); //اياكككك تلعب هنا لا تحط توكنك هنا
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement