Advertisement
n3k4a

Music Code Speed and small :)

Feb 13th, 2020
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.85 KB | None | 0 0
  1.  
  2. /* تم نشر هذا الكود في سيرفر توكسك كودز واي احد غيرنا يستعمله يعد ك سرقه
  3.  
  4. وسوف يتم تبنيده من الدسكورد علي يدي */
  5.  
  6. const Discord = require('discord.js');
  7. const Util = require('discord.js');
  8. const getYoutubeID = require('get-youtube-id');
  9. const fetchVideoInfo = require('youtube-info');
  10. const YouTube = require('simple-youtube-api');
  11. const youtube = new YouTube("AIzaSyAdORXg7UZUo7sePv97JyoDqtQVi3Ll0b8");
  12. const queue = new Map();
  13. const ytdl = require('ytdl-core');
  14. const fs = require('fs');
  15.  
  16.  
  17.  
  18. client.on('ready',async () => {
  19. client.channels.find(ch => ch.id === "ايدي حق الروم لي يثبت بيها البوت" && ch.type === 'voice').join();
  20. });
  21.  
  22. const client = new Discord.Client({disableEveryone: true});
  23.  
  24. const prefix = "#";/// البريفكس حق البوت
  25.  
  26. client.on('message', async msg =>{
  27. if (msg.author.bot) return undefined;
  28. if (!msg.content.startsWith(prefix)) return undefined;
  29.  
  30. let args = msg.content.split(' ');
  31.  
  32. let command = msg.content.toLowerCase().split(" ")[0];
  33. command = command.slice(prefix.length)
  34.  
  35. if(command === `ping`) {
  36. let embed = new Discord.RichEmbed()
  37. .setColor(3447003)
  38. .setTitle("Pong!!")
  39. .setDescription(`${client.ping} ms,`)
  40. .setFooter(`Requested by | ${msg.author.tag}`);
  41. msg.delete().catch(O_o=>{})
  42. msg.channel.send(embed);
  43. }
  44. });
  45.  
  46. client.on('message', async msg =>{
  47. if (msg.author.bot) return undefined;
  48. if (!msg.content.startsWith(prefix)) return undefined;
  49.  
  50. let args = msg.content.split(' ');
  51.  
  52. let command = msg.content.toLowerCase().split(" ")[0];
  53. command = command.slice(prefix.length)
  54.  
  55. if(command === `avatar`){
  56. if(msg.channel.type === 'dm') return msg.channel.send("Nope Nope!! u can't use avatar command in DMs (:")
  57. let mentions = msg.mentions.members.first()
  58. if(!mentions) {
  59. let sicon = msg.author.avatarURL
  60. let embed = new Discord.RichEmbed()
  61. .setImage(msg.author.avatarURL)
  62. .setColor("#5074b3")
  63. msg.channel.send({embed})
  64. } else {
  65. let sicon = mentions.user.avatarURL
  66. let embed = new Discord.RichEmbed()
  67. .setColor("#5074b3")
  68. .setImage(sicon)
  69. msg.channel.send({embed})
  70. }
  71. };
  72. });
  73.  
  74.  
  75.  
  76. client.on('message', async msg => {
  77. if (msg.author.bot) return undefined;
  78. if (!msg.content.startsWith(prefix)) return undefined;
  79.  
  80. const args = msg.content.split(' ');
  81. const searchString = args.slice(1).join(' ');
  82.  
  83. const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
  84. const serverQueue = queue.get(msg.guild.id);
  85.  
  86. let command = msg.content.toLowerCase().split(" ")[0];
  87. command = command.slice(prefix.length)
  88.  
  89.  
  90. if (command === `play`) {
  91.  
  92.  
  93. const voiceChannel = msg.member.voiceChannel;
  94.  
  95. if (!voiceChannel) return msg.channel.send(":no_entry_sign: You must join a voice channel to use that!");
  96.  
  97. const permissions = voiceChannel.permissionsFor(msg.client.user);
  98.  
  99. if (!permissions.has('CONNECT')) {
  100.  
  101. return msg.channel.send("You Don't Have to join is channel");
  102. }
  103.  
  104. if (!permissions.has('SPEAK')) {
  105.  
  106. return msg.channel.send("You can't speak in this room");
  107. }
  108.  
  109. if (!permissions.has('EMBED_LINKS')) {
  110.  
  111. return msg.channel.sendMessage( 'Ido not have permission ``EMBED_LINKS`` ')
  112. }
  113. voiceChannel.join()
  114.  
  115. if(!args[1]) return msg.channel.send(`:bulb: Play Commands:
  116.  
  117. \`\`${prefix}play <song title>\`\` - plays the first result from Youtube
  118. \`\`${prefix}play <URL>\`\` - plays the provided song, playlist, or stream`)
  119.  
  120.  
  121. if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  122.  
  123. const playlist = await youtube.getPlaylist(url);
  124. const videos = await playlist.getVideos();
  125.  
  126.  
  127. for (const video of Object.values(videos)) {
  128.  
  129. const video2 = await youtube.getVideoByID(video.id);
  130. await handleVideo(video2, msg, voiceChannel, true);
  131. }
  132. return msg.channel.send(`**${playlist.title}**, Just added to the queue!`);
  133. } else {
  134.  
  135. try {
  136.  
  137. var video = await youtube.getVideo(url);
  138.  
  139. } catch (error) {
  140. try {
  141.  
  142. var videos = await youtube.searchVideos(searchString, 5);
  143. let index = 0;
  144. const embed1 = new Discord.RichEmbed()
  145. .setTitle(":mag_right: YouTube Search Results :")
  146. .setDescription(`
  147. ${videos.map(video2 => `${++index}. **${video2.title}**`).join('\n')}`)
  148.  
  149. .setColor("#f7abab")
  150.  
  151.  
  152. /////////////////
  153.  
  154.  
  155. var video = await youtube.getVideoByID(videos[0].id);
  156.  
  157. } catch (err) {
  158.  
  159. console.error(err);
  160. return msg.channel.send("I didn't find any results!");
  161. }
  162. }
  163.  
  164. return handleVideo(video, msg, voiceChannel);
  165.  
  166. }
  167.  
  168. } else if (command === `skip`) {
  169.  
  170. if (!msg.member.voiceChannel) return msg.channel.send(":no_entry_sign: You must join a voice channel to use that!");
  171. if (!serverQueue) return ;
  172.  
  173. serverQueue.connection.dispatcher.end( `:notes: Skipped asdasd - <@${msg.author.id}>`);
  174. msg.channel.send( `:notes: Skipped asdasd - <@${msg.author.id}>`);
  175.  
  176. return undefined;
  177.  
  178. } else if (command === `stop`) {
  179.  
  180. if (!msg.member.voiceChannel) return msg.channel.send(":no_entry_sign: You must join a voice channel to use that!");
  181. if (!serverQueue) return msg.channel.send(":notes: The player has stopped and the queue has been cleared.");
  182.  
  183.  
  184. serverQueue.songs = [];
  185. serverQueue.connection.dispatcher.end(':notes: The player has stopped and the queue has been cleared.');
  186. return undefined;
  187.  
  188. } else if (command === `vol`) {
  189.  
  190. if (!msg.member.voiceChannel) return msg.channel.send(":no_entry_sign: You must join a voice channel to use that!");
  191. if (!serverQueue) return msg.channel.send(' The bot is not playing :interrobang:');
  192. if (!args[1]) return msg.channel.send(`:speaker: Current volume is **${serverQueue.volume}**`);
  193. if(args[1] > 100 || args[1] <10) return msg.channel.send(':no_entry_sign: Volume must be a valid integer between ``10`` and ``100``' )
  194.  
  195. serverQueue.volume = args[1];
  196.  
  197. serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 100);
  198.  
  199. return msg.channel.send(`:loud_sound: Volume changed on \`\`${args[1]}\`\``);
  200.  
  201. } else if (command === `np`) {
  202.  
  203. if (!serverQueue) return msg.channel.send('There is no Queue!');
  204.  
  205. return msg.channel.send(`:arrow_forward: **${serverQueue.songs[0].title}**`)
  206.  
  207. } else if (command === `queue`) {
  208.  
  209. if (!serverQueue) return msg.channel.send('There is no Queue!!');
  210. // // //
  211. const embedqu = new Discord.RichEmbed()
  212. .setTitle(`:notes: Current Queue | ${serverQueue.songs.length -1} entries`)
  213. .setDescription(`
  214. ${serverQueue.songs.map((song,index) => index ==0 ?null : `**[${index}]** ${song.title} - `).join('\n')}`)
  215. .setColor("#4f545c")
  216. return msg.channel.send(`:arrow_forward: **${serverQueue.songs[0].title}**`).then((a)=>{
  217. msg.channel.sendEmbed(embedqu);
  218. })
  219.  
  220. } else if (command === `pause`) {
  221. if (serverQueue && serverQueue.playing) {
  222. serverQueue.playing = false;
  223. serverQueue.connection.dispatcher.pause();
  224. return msg.channel.send(` :notes: Paused **${serverQueue.songs[0].title}** `);
  225. }
  226. return msg.channel.send(' The player is already paused! Use '+prefix+'``resume`` to unpause!');
  227. } else if (command === "resume") {
  228. // سنايس
  229. if (serverQueue && !serverQueue.playing) {
  230. serverQueue.playing = true;
  231. serverQueue.connection.dispatcher.resume();
  232. return msg.channel.send(`:notes: Resumed **${serverQueue.songs[0].title}** `);
  233.  
  234. }
  235. return msg.channel.send('Queue is empty!');
  236. }
  237.  
  238. return undefined;
  239. });
  240.  
  241. async function handleVideo(video, msg, voiceChannel, playlist = false) {
  242. const serverQueue = queue.get(msg.guild.id);
  243. console.log(video);
  244.  
  245.  
  246. const song = {
  247. id: video.id,
  248. title: Util.escapeMarkdown(video.title),
  249. url: `https://www.youtube.com/watch?v=${video.id}`,
  250. user: msg.author
  251. };
  252. if (!serverQueue) {
  253. const queueConstruct = {
  254. textChannel: msg.channel,
  255. voiceChannel: voiceChannel,
  256. connection: null,
  257. songs: [],
  258. volume: 7.5,
  259. playing: true
  260. };
  261. queue.set(msg.guild.id, queueConstruct);
  262.  
  263. queueConstruct.songs.push(song);
  264.  
  265. try {
  266. var connection = await voiceChannel.join();
  267. queueConstruct.connection = connection;
  268. play(msg.guild, queueConstruct.songs[0]);
  269. } catch (error) {
  270. console.error(`I could not join the voice channel: ${error}!`);
  271. queue.delete(msg.guild.id);
  272. return msg.channel.send(`Can't join this channel: ${error}!`);
  273. }
  274. } else {
  275. serverQueue.songs.push(song);
  276. console.log(serverQueue.songs);
  277. if (playlist) return undefined;
  278. else return msg.channel.send(` :notes: **${song.title}** Added to **Queue** !`);
  279. }
  280. return undefined;
  281. }
  282.  
  283. function play(guild, song) {
  284. const serverQueue = queue.get(guild.id);
  285.  
  286. if (!song) {
  287. queue.delete(guild.id);
  288. return;
  289. }
  290. console.log(serverQueue.songs);
  291.  
  292. const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  293. .on('end', reason => {
  294. if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
  295. else console.log(reason);
  296. serverQueue.songs.shift();
  297. play(guild, serverQueue.songs[0]);
  298. })
  299. .on('error', error => console.error(error));
  300. dispatcher.setVolumeLogarithmic(serverQueue.volume / 8);
  301.  
  302. serverQueue.textChannel.send(` :notes: **${song.title}** Added to **Queue** !`);
  303. }
  304.  
  305.  
  306.  
  307. client.on("message", async message => {
  308. let sm ={}
  309. const argsa = message.content.slice(prefix.length).trim().split(/ +/g);
  310. const command = argsa.shift().toLowerCase();
  311. if(message.author.bot) return;
  312. if(message.content.indexOf(prefix) !== 0) return;
  313.  
  314. if (command == "help") {
  315.  
  316. message.react('🎶');
  317.  
  318. let botembed = new Discord.RichEmbed()
  319.  
  320. .setTitle('**Music Commande...**')
  321. .setDescription(`Bot prefix < **${prefix}** >`)
  322. .addField('play', 'start music ')
  323. .addField('skip', 'Skip the song')
  324. .addField('pause', 'Pause the song')
  325. .addField('resume', 'unpause')
  326. .addField('queue', 'shows the current queue')
  327. .addField('np', 'Show the song you are currently playing')
  328.  
  329. .setFooter(`${message.author.username}`, message.author.displayAvatarURL);
  330.  
  331.  
  332. return message.author.send(botembed);
  333.  
  334.  
  335. }
  336.  
  337. });
  338.  
  339.  
  340.  
  341. client.login('');/// توكن البوت
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement