Guest User

Untitled

a guest
Dec 22nd, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const yt = require('ytdl-core');
  3. const config = require('./config.json');
  4. const client = new Discord.Client();
  5. var opus = require('opusscript');
  6.  
  7. let queue = {};
  8.  
  9. client.on('ready', () => {
  10. console.log('506 said you are good to go!');
  11. client.user.setGame("مشوووش");
  12. });
  13.  
  14. client.on('guildMemberAdd', (member) => {
  15. let guild = member.guild;
  16. member.sendMessage("مرحبا.");
  17. });
  18.  
  19. client.on('guildCreate', guild => {
  20. console.log('New guild added: ${guild.name}, owned by ${guild.owner.user.username}')
  21.  
  22. });
  23.  
  24. client.on('message', message => { // ALL commands should go in here.
  25.  
  26.  
  27.  
  28.  
  29. if (message.author.bot) return; // Removes the possibility of the bot replying to itself
  30. if (!message.content.startsWith(config.prefix)) return; // Only lets the bots read messages that start with *
  31.  
  32.  
  33. let command = message.content.split(' ')[0];
  34. command = command.slice(config.prefix.length);
  35. console.log(command); // Logs all Commands
  36.  
  37. let args = message.content.split(' ').slice(1);
  38.  
  39.  
  40. if (command === 'مساعده') {
  41. message.channel.sendMessage('__**Music Commands**__ \n ```' + config.prefix + 'join : Join Voice channel of message sender \n' + config.prefix + 'add : Add a valid youtube link to the queue \n' + config.prefix + 'queue : Shows the current queue, up to 15 songs shown. \n' + config.prefix + 'play : Play the music queue if already joined to a voice channel \n' + '' + 'the following commands only function while the play command is running: \n'.toUpperCase() + config.prefix + 'pause : pauses the music \n' + config.prefix + 'resume : "resumes the music \n' + config.prefix + 'skip : skips the playing song \n' + config.prefix + 'time : Shows the playtime of the song.' + 'volume+(+++) : increases volume by 2%/+' + 'volume-(---) : decreases volume by 2%/- \n' + '```')
  42. }
  43.  
  44. if (command === 'شغل') {
  45. if (queue[message.guild.id] === undefined) return message.channel.sendMessage(`Add some songs to the queue first with ${config.prefix}add`); //Add some songs if the queue is empty.
  46. if (!message.guild.voiceConnection) return commands.join(message).then(() => commands.play(message));
  47. if (queue[message.guild.id].playing) return message.channel.sendMessage('Already Playing');
  48. let dispatcher;
  49. queue[message.guild.id].playing = true;
  50.  
  51. console.log(queue);
  52. (function play(song) {
  53. console.log(song);
  54. if (song === undefined) return message.channel.sendMessage('Queue is empty').then(() => {
  55. queue[message.guild.id].playing = false;
  56. message.member.voiceChannel.leave();
  57. });
  58. message.channel.sendMessage(`Playing: **${song.title}** as requested by: **${song.requester}**`);
  59. dispatcher = message.guild.voiceConnection.playStream(yt(song.url, { audioonly: true }), { passes: config.passes });
  60. let collector = message.channel.createCollector(m => m);
  61. collector.on('message', m => {
  62. if (m.content.startsWith(config.prefix + 'وقف')) {
  63. message.channel.sendMessage('paused').then(() => { dispatcher.pause(); });
  64. } else if (m.content.startsWith(config.prefix + 'R')) {
  65. message.channel.sendMessage('resumed').then(() => { dispatcher.resume(); });
  66. } else if (m.content.startsWith(config.prefix + 'S')) {
  67. message.channel.sendMessage('skipped').then(() => { dispatcher.end(); });
  68. } else if (m.content.startsWith('volume+')) {
  69. if (Math.round(dispatcher.volume * 50) >= 100) return message.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume * 50)}%`);
  70. dispatcher.setVolume(Math.min((dispatcher.volume * 50 + (2 * (m.content.split('+').length - 1))) / 50, 2));
  71. message.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume * 50)}%`);
  72. } else if (m.content.startsWith('volume-')) {
  73. if (Math.round(dispatcher.volume * 50) <= 0) return message.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume * 50)}%`);
  74. dispatcher.setVolume(Math.max((dispatcher.volume * 50 - (2 * (m.content.split('-').length - 1))) / 50, 0));
  75. message.channel.sendMessage(`Volume: ${Math.round(dispatcher.volume * 50)}%`);
  76. } else if (m.content.startsWith(config.prefix + 'time')) {
  77. message.channel.sendMessage(`time: ${Math.floor(dispatcher.time / 60000)}:${Math.floor((dispatcher.time % 60000) / 1000) < 10 ? '0' + Math.floor((dispatcher.time % 60000) / 1000) : Math.floor((dispatcher.time % 60000) / 1000)}`);
  78. }
  79. });
  80. dispatcher.on('end', () => {
  81. collector.stop();
  82. });
  83. dispatcher.on('error', (err) => {
  84. return message.channel.sendMessage('error: ' + err).then(() => {
  85. collector.stop();
  86. play(queue[message.guild.id].songs.shift());
  87. });
  88. });
  89. })(queue[message.guild.id].songs[0]);
  90. }
  91.  
  92. if (command === 'join') {
  93. return new Promise((resolve, reject) => {
  94. const voiceChannel = message.member.voiceChannel;
  95. if (!voiceChannel || voiceChannel.type !== 'voice') return message.reply('I couldn\'t connect to your voice channel...');
  96. voiceChannel.join().then(connection => resolve(connection)).catch(err => reject(err));
  97. });
  98. }
  99.  
  100. if (command === 'add') {
  101. let url = message.content.split(' ')[1];
  102. if (url == '' || url === undefined) return message.channel.sendMessage(`You must add a url, or youtube video id after ${config.prefix}add`);
  103. yt.getInfo(url, (err, info) => {
  104. if (err) return message.channel.sendMessage('Invalid YouTube Link: ' + err);
  105. if (!queue.hasOwnProperty(message.guild.id)) queue[message.guild.id] = {}, queue[message.guild.id].playing = false, queue[message.guild.id].songs = [];
  106. queue[message.guild.id].songs.push({ url: url, title: info.title, requester: message.author.username });
  107. message.channel.sendMessage(`added **${info.title}** to the queue`);
  108. });
  109. }
  110.  
  111. if (command === 'queue') {
  112. if (queue[message.guild.id] === undefined) return message.channel.sendMessage(`Add some songs to the queue first with ${config.prefix}add`);
  113. let tosend = [];
  114. queue[message.guild.id].songs.forEach((song, i) => { tosend.push(`${i + 1}. ${song.title} - Requested by: ${song.requester}`); });
  115. message.channel.sendMessage(`__**${message.guild.name}'s Music Queue:**__ Currently **${tosend.length}** songs queued ${(tosend.length > 15 ? '*[Only next 15 shown]*' : '')}\n\`\`\`${tosend.slice(0, 15).join('\n')}\`\`\``);
  116. }
  117.  
  118. if (command === 'about') {
  119. message.channel.sendMessage("Made For XM506")
  120. }
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. });
  128.  
  129. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment