Advertisement
Guest User

Music By Jake

a guest
Feb 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.24 KB | None | 0 0
  1. const Discord = require('discord.js');
  2.  
  3. const Util = require('discord.js');
  4.  
  5. const getYoutubeID = require('get-youtube-id');
  6.  
  7. const fetchVideoInfo = require('youtube-info');
  8.  
  9. const YouTube = require('simple-youtube-api');
  10.  
  11. const youtube = new YouTube("AIzaSyDLDoUv5Oca_Hd1QbTFL0jN6M6wWqn7njA");
  12.  
  13. const queue = new Map();
  14.  
  15. const ytdl = require('ytdl-core');
  16.  
  17. const fs = require('fs');
  18.  
  19. const gif = require("gif-search");
  20.  
  21. const client = new Discord.Client({disableEveryone: true});
  22.  
  23. const prefix = "1";
  24. /////////////////////////
  25. ////////////////////////
  26.  
  27.  
  28. client.on('ready', () => {
  29. console.log(`Logged in as ${client.user.tag} !`);
  30. client.user.setGame(`1help `, `www.twitch.tv/v5bz`);
  31. });
  32.  
  33. const devs1 = ['510831122238668833','480407581085532180'];
  34.  
  35. client.on('message', message => {
  36. let argresult = message.content.split(` `).slice(1).join(' ');
  37. if (message.content.startsWith(prefix + 'setStreaming')) {
  38. if (!devs1.includes(message.author.id)) return message.channel.send("<@480407581085532180> only this guy can do restart the bot so don't try again :wink:.");
  39. message.delete();
  40. client.user.setGame(argresult, 'https://twitch.tv/DynastyShop');
  41.  
  42. } else if(message.content.startsWith(prefix + 'setWatching')) {
  43. client.user.setActivity(argresult,{type: 'WATCHING'});
  44.  
  45. } else if(message.content.startsWith(prefix + 'setListening')) {
  46. client.user.setActivity(argresult,{type: 'LISTENING'});
  47.  
  48. } else if(message.content.startsWith(prefix + 'setPlaying')) {
  49. client.user.setActivity(argresult,{type: 'PLAYING'});
  50.  
  51. } else if(message.content.startsWith(prefix + 'setName')) {
  52. client.user.setUsername(argresult);
  53.  
  54. } else if(message.content.startsWith(prefix + 'setAvatar')) {
  55. client.user.setAvatar(argresult);
  56.  
  57.  
  58. } else if(message.content.startsWith(prefix + 'setStatus')) {
  59. if(!argresult) return message.channel.send('`online`, `DND(Do not Distrub),` `idle`, `invisible(Offline)` :notes: أختر أحد الحالات');
  60. client.user.setStatus(argresult);
  61.  
  62.  
  63. }
  64.  
  65. });
  66.  
  67. client.on('message', async msg =>{
  68. if (msg.author.bot) return undefined;
  69. if (!msg.content.startsWith(prefix)) return undefined;
  70.  
  71. let args = msg.content.split(' ');
  72.  
  73. let command = msg.content.toLowerCase().split(" ")[0];
  74. command = command.slice(prefix.length)
  75.  
  76. if(command === `ping`) {
  77. let embed = new Discord.RichEmbed()
  78. .setColor(3447003)
  79. .setTitle("Pong!!")
  80. .setDescription(`${client.ping} ms,`)
  81. .setFooter(`Requested by | ${msg.author.tag}`);
  82. msg.delete().catch(O_o=>{})
  83. msg.channel.send(embed);
  84. }
  85. });
  86. /////////////////////////
  87. ////////////////////////
  88. //////////////////////
  89. client.on('message', async msg =>{
  90. if (msg.author.bot) return undefined;
  91. if (!msg.content.startsWith(prefix)) return undefined;
  92.  
  93. let args = msg.content.split(' ');
  94.  
  95. let command = msg.content.toLowerCase().split(" ")[0];
  96. command = command.slice(prefix.length)
  97.  
  98. if(command === `avatar`){
  99. if(msg.channel.type === 'dm') return msg.channel.send("Nope Nope!! u can't use avatar command in DMs (:")
  100. let mentions = msg.mentions.members.first()
  101. if(!mentions) {
  102. let sicon = msg.author.avatarURL
  103. let embed = new Discord.RichEmbed()
  104. .setImage(msg.author.avatarURL)
  105. .setColor("#5074b3")
  106. msg.channel.send({embed})
  107. } else {
  108. let sicon = mentions.user.avatarURL
  109. let embed = new Discord.RichEmbed()
  110. .setColor("#5074b3")
  111. .setImage(sicon)
  112. msg.channel.send({embed})
  113. }
  114. };
  115. });
  116. /////////////////////////
  117. ////////////////////////
  118. //////////////////////
  119. /////////////////////////
  120. ////////////////////////
  121. //////////////////////
  122.  
  123. /////////////////////////
  124. ////////////////////////
  125. //////////////////////
  126. /////////////////////////
  127. ////////////////////////
  128. //////////////////////
  129. client.on('message', async msg => {
  130. if (msg.author.bot) return undefined;
  131. if (!msg.content.startsWith(prefix)) return undefined;
  132.  
  133. const args = msg.content.split(' ');
  134. const searchString = args.slice(1).join(' ');
  135.  
  136. const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
  137. const serverQueue = queue.get(msg.guild.id);
  138.  
  139. let command = msg.content.toLowerCase().split(" ")[0];
  140. command = command.slice(prefix.length)
  141.  
  142. if (command === `play`) {
  143. const voiceChannel = msg.member.voiceChannel;
  144.  
  145. if (!voiceChannel) return msg.channel.send("I can't find you in any voice channel!");
  146.  
  147. const permissions = voiceChannel.permissionsFor(msg.client.user);
  148.  
  149. if (!permissions.has('CONNECT')) {
  150.  
  151. return msg.channel.send("I don't have enough permissions to join your voice channel!");
  152. }
  153.  
  154. if (!permissions.has('SPEAK')) {
  155.  
  156. return msg.channel.send("I don't have enough permissions to speak in your voice channel!");
  157. }
  158.  
  159. if (!permissions.has('EMBED_LINKS')) {
  160.  
  161. return msg.channel.sendMessage("I don't have enough permissions to insert a URLs!")
  162. }
  163.  
  164. if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  165.  
  166. const playlist = await youtube.getPlaylist(url);
  167. const videos = await playlist.getVideos();
  168.  
  169.  
  170. for (const video of Object.values(videos)) {
  171.  
  172. const video2 = await youtube.getVideoByID(video.id);
  173. await handleVideo(video2, msg, voiceChannel, true);
  174. }
  175. return msg.channel.send(`**${playlist.title}**, Just added to the queue!`);
  176. } else {
  177.  
  178. try {
  179.  
  180. var video = await youtube.getVideo(url);
  181.  
  182. } catch (error) {
  183. try {
  184.  
  185. var videos = await youtube.searchVideos(searchString, 5);
  186. let index = 0;
  187. const embed1 = new Discord.RichEmbed()
  188. .setTitle(":mag_right: YouTube Search Results :")
  189. .setDescription(`
  190. ${videos.map(video2 => `${++index}. **${video2.title}**`).join('\n')}`)
  191.  
  192. .setColor("#f7abab")
  193. msg.channel.sendEmbed(embed1).then(message =>{message.delete(20000)})
  194.  
  195. /////////////////
  196. try {
  197.  
  198. var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
  199. maxMatches: 1,
  200. time: 15000,
  201. errors: ['time']
  202. });
  203. } catch (err) {
  204. console.error(err);
  205. return msg.channel.send('No one respone a number!!');
  206. }
  207.  
  208. const videoIndex = parseInt(response.first().content);
  209. var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
  210.  
  211. } catch (err) {
  212.  
  213. console.error(err);
  214. return msg.channel.send("I didn't find any results!");
  215. }
  216. }
  217.  
  218. return handleVideo(video, msg, voiceChannel);
  219.  
  220. }
  221.  
  222. } else if (command === `skip`) {
  223.  
  224. if (!msg.member.voiceChannel) return msg.channel.send("You Must be in a Voice channel to Run the Music commands!");
  225. if (!serverQueue) return msg.channel.send("There is no Queue to skip!!");
  226.  
  227. serverQueue.connection.dispatcher.end('Ok, skipped!');
  228. return undefined;
  229.  
  230. } else if (command === `stop`) {
  231.  
  232. if (!msg.member.voiceChannel) return msg.channel.send("You Must be in a Voice channel to Run the Music commands!");
  233. if (!serverQueue) return msg.channel.send("There is no Queue to stop!!");
  234.  
  235. serverQueue.songs = [];
  236. serverQueue.connection.dispatcher.end('Ok, stopped & disconnected from your Voice channel');
  237. return undefined;
  238.  
  239. } else if (command === `vol`) {
  240.  
  241. if (!msg.member.voiceChannel) return msg.channel.send("You Must be in a Voice channel to Run the Music commands!");
  242. if (!serverQueue) return msg.channel.send('You only can use this command while music is playing!');
  243. if (!args[1]) return msg.channel.send(`The bot volume is **${serverQueue.volume}**`);
  244.  
  245. serverQueue.volume = args[1];
  246. serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 50);
  247.  
  248. return msg.channel.send(`Volume Now is **${args[1]}**`);
  249.  
  250. } else if (command === `np`) {
  251.  
  252. if (!serverQueue) return msg.channel.send('There is no Queue!');
  253. const embedNP = new Discord.RichEmbed()
  254. .setDescription(`Now playing **${serverQueue.songs[0].title}**`)
  255. return msg.channel.sendEmbed(embedNP);
  256.  
  257. } else if (command === `queue`) {
  258.  
  259. if (!serverQueue) return msg.channel.send('There is no Queue!!');
  260. let index = 0;
  261. // // //
  262. const embedqu = new Discord.RichEmbed()
  263. .setTitle("The Queue Songs :")
  264. .setDescription(`
  265. ${serverQueue.songs.map(song => `${++index}. **${song.title}**`).join('\n')}
  266. **Now playing :** **${serverQueue.songs[0].title}**`)
  267. .setColor("#f7abab")
  268. return msg.channel.sendEmbed(embedqu);
  269. } else if (command === `pause`) {
  270. if (serverQueue && serverQueue.playing) {
  271. serverQueue.playing = false;
  272. serverQueue.connection.dispatcher.pause();
  273. return msg.channel.send('Ok, paused');
  274. }
  275. return msg.channel.send('There is no Queue to Pause!');
  276. } else if (command === "resume") {
  277.  
  278. if (serverQueue && !serverQueue.playing) {
  279. serverQueue.playing = true;
  280. serverQueue.connection.dispatcher.resume();
  281. return msg.channel.send('Ok, resumed!');
  282.  
  283. }
  284. return msg.channel.send('Queue is empty!');
  285. }
  286.  
  287. return undefined;
  288. });
  289.  
  290. async function handleVideo(video, msg, voiceChannel, playlist = false) {
  291. const serverQueue = queue.get(msg.guild.id);
  292. console.log(video);
  293.  
  294.  
  295. const song = {
  296. id: video.id,
  297. title: Util.escapeMarkdown(video.title),
  298. url: `https://www.youtube.com/watch?v=${video.id}`
  299. };
  300. if (!serverQueue) {
  301. const queueConstruct = {
  302. textChannel: msg.channel,
  303. voiceChannel: voiceChannel,
  304. connection: null,
  305. songs: [],
  306. volume: 5,
  307. playing: true
  308. };
  309. queue.set(msg.guild.id, queueConstruct);
  310.  
  311. queueConstruct.songs.push(song);
  312.  
  313. try {
  314. var connection = await voiceChannel.join();
  315. queueConstruct.connection = connection;
  316. play(msg.guild, queueConstruct.songs[0]);
  317. } catch (error) {
  318. console.error(`I could not join the voice channel: ${error}!`);
  319. queue.delete(msg.guild.id);
  320. return msg.channel.send(`Can't join this channel: ${error}!`);
  321. }
  322. } else {
  323. serverQueue.songs.push(song);
  324. console.log(serverQueue.songs);
  325. if (playlist) return undefined;
  326. else return msg.channel.send(`**${song.title}**, just added to the queue! `);
  327. }
  328. return undefined;
  329. }
  330.  
  331. function play(guild, song) {
  332. const serverQueue = queue.get(guild.id);
  333.  
  334. if (!song) {
  335. serverQueue.voiceChannel.leave();
  336. queue.delete(guild.id);
  337. return;
  338. }
  339. console.log(serverQueue.songs);
  340.  
  341. const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  342. .on('end', reason => {
  343. if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
  344. else console.log(reason);
  345. serverQueue.songs.shift();
  346. play(guild, serverQueue.songs[0]);
  347. })
  348. .on('error', error => console.error(error));
  349. dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  350.  
  351. serverQueue.textChannel.send(`**${song.title}**, is now playing!`);
  352. }
  353. client.on('message', message => {
  354. if (message.author.bot) return;
  355. if (message.content === prefix + "help") {
  356. message.channel.send('**The Message Was Sent On Private**');
  357.  
  358.  
  359.  
  360.  
  361.  
  362. message.author.sendMessage(`
  363. **
  364. By: JakeY#2019
  365. ╔[❖════════════❖]╗
  366. Prefix = ' 1 '
  367. ╚[❖════════════❖]╝
  368. ╔[❖════════════❖]╗
  369. Music Commands كومندات الميوزك
  370. ╚[❖════════════❖]╝
  371. ❖ 1play ➾ play a song تشغل اغنية برابط او اسم
  372. ❖ 1stop ➾ stop the song توقف البوت نهائيا
  373.  
  374. ❖ 1np ➾ view the current song تشوف الاغنية اللي مشغلة حاليا
  375. ❖ 1queue ➾ the current playlist تشوف قائمة التشغيل الحالية
  376. ❖ 1skip ➾ skips a song تتجاوز اغنية
  377.  
  378. ❖ 1resume ➾ resums a song تشغل الاغنية بعد التوقيف المؤقت
  379. ❖ 1pause ➾ pauses a song تووقف اغنية مؤقتا
  380. تخلي البوت يخرج من رومك الصوتي
  381. ╔[❖════════════❖]╗
  382. General Commands كومندات عامة
  383. ╚[❖════════════❖]╝
  384. ❖ 1ping ➾ view my ping ! تشوف سرعة اتصال البوت
  385. ==================================================================
  386. ==================================================================
  387. `);
  388.  
  389. }
  390. });
  391.  
  392. client.on('message', message => {
  393. if (message.content === '1general_commands') {
  394. let helpEmbed = new Discord.RichEmbed()
  395. .setTitle('**أوامر عامة...**')
  396. .addField('avatar', "افاتار الشخص المطلوب")
  397. .addField('gif', 'البحث عن جيف انت تطلبه')
  398. .addField('ping', 'معرفة ping البوت')
  399.  
  400. .setFooter('المزيد قريبا ان شاء الله!')
  401. message.channel.send(helpEmbed);
  402. }
  403. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement