daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 306 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, RichEmbed } = require("discord.js");
  2. const client = new Client({ disableEveryone: true})
  3. const ytdl = require("ytdl-core");
  4. const devs = ["" , "" , "" , "id"]
  5. const request = require("request");
  6. const convert = require("hh-mm-ss")
  7. const fs = require("fs");
  8. const getYouTubeID = require("get-youtube-id");
  9. const fetchVideoInfo = require("youtube-info");
  10. const simpleytapi = require('simple-youtube-api')
  11. const yt_api_key = "AIzaSyDoH9YxF0yi6ljyi2txYZHB10vXNUEP_2U"
  12. const prefix = "m-";
  13. client.login(process.env.SECERT_KEY);
  14. var guilds = {};
  15. /////////////////////////////////////////////////////////////////
  16. client.on('error', (err) => console.log(err));
  17. client.on('ready', () => console.log(`Launching...`))
  18. /////////////////////////////////////////////////////////////////////////////////
  19.  
  20. client.on('message', async function(message) {
  21.     if(message.author.bot) return;
  22.     if(!message.channel.guild) return;
  23.     //////////////////////////////////
  24.     if(message.content === `<@${client.user.id}>`) return message.channel.send(`Hey I'am **${client.user.username}**, A nice music bot developed by: \`\`Abady#1196\`\``);
  25.     // const noms = "** ❯ :musical_note: No music is playing, try ``m-play``"
  26.     const novc = "**<:MxNo:449703922190385153> | You are not in a voice channel.**"
  27.     // const nomatch = "**<:MxNo:449703922190385153> You've to be in the same voice channel!**"
  28.     const yt = "<:MxYT:451042476552355841>"
  29.     const correct = client.guilds.get('448425456316973057').emojis.get("451040030635458574")
  30.     const nope = client.guilds.get('448425456316973057').emojis.get('451040031277056001')
  31.     // const member = message.member;
  32.  
  33.     if (message.content.startsWith(`${prefix}eval`)) {
  34.         const eargs = message.content.split(" ").slice(1);
  35.         if(!devs.includes(message.author.id)) return;
  36.         const clean = text => {
  37.             if (typeof(text) === "string")
  38.               return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
  39.             else
  40.                 return text;
  41.           }
  42.         try {
  43.           const code = eargs.join(" ");
  44.           let evaled = eval(code);
  45.    
  46.           if (typeof evaled !== "string")
  47.             evaled = require("util").inspect(evaled);    
  48.           message.channel.send(clean(evaled), {code:"xl"});
  49.         } catch (err) {
  50.           message.channel.send(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
  51.         }
  52.       }
  53.  
  54.       if(message.content.startsWith(`${prefix}info`)) {
  55.         function convertMS(ms) {
  56.             var d, h, m, s;
  57.             s = Math.floor(ms / 1000);
  58.             m = Math.floor(s / 60);
  59.             s = s % 60;
  60.             h = Math.floor(m / 60);
  61.             m = m % 60;
  62.             d = Math.floor(h / 24);
  63.             h = h % 24;
  64.             return {
  65.                 d: d,
  66.                 h: h,
  67.                 m: m,
  68.                 s: s
  69.             };
  70.         };  
  71.         let u = convertMS(client.uptime);
  72.         let uptime = u.d + " days  , " + u.h + " hrs  , " + u.m + " mins  , " + u.s + " secs"
  73.         message.channel.send(new RichEmbed()
  74.         .setAuthor(client.user.username,client.user.avatarURL)
  75.         .setURL("https://abayro.xyz")
  76.         .addField("Version", "1.0v", true)
  77.         .addField("Library", "[discordjs](https://www.npmjs.com/search?q=discord.js)", true)
  78.         .addField("Creator", "Abady", true)
  79.         .addField("Users", `${client.users.size}`, true)
  80.         .addField('RAM Usage',`${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,true)    
  81.         .addField("Website", "No website atm", true)
  82.         .setFooter("Uptime "+`${uptime}`)
  83.         .setColor("RANDOM")
  84.     )
  85.       }
  86.    
  87.     const mess = message.content.toLowerCase();
  88.     const args = message.content.split(' ').slice(1).join(" ");
  89.     const youtube = new simpleytapi(yt_api_key);
  90.  
  91.     if (!guilds[message.guild.id]) {
  92.         guilds[message.guild.id] = {
  93.             queue: [],
  94.             queueNames: [],
  95.             isPlaying: false,
  96.             dispatcher: null,
  97.             voiceChannel: null,
  98.             volume: 1,
  99.             skipReq: 0,
  100.             skippers: [],
  101.             loop: false
  102.         };
  103.     }
  104.  
  105.     function clear() {
  106.         guilds[message.guild.id].queue = [];
  107.         guilds[message.guild.id].queueNames = [];
  108.         guilds[message.guild.id].isPlaying = false;
  109.         guilds[message.guild.id].dispatcher = null
  110.         guilds[message.guild.id].voiceChannel = null;
  111.         guilds[message.guild.id].skipReq = 0;
  112.         guilds[message.guild.id].skipReq = [];
  113.         guilds[message.guild.id].loop = false;
  114.         guilds[message.guild.id].volume = 1 ;
  115.     }
  116.  
  117.  
  118.     if (mess.startsWith(prefix + "play") || mess.startsWith(prefix+"شغل")) {
  119.         if (message.member.voiceChannel || guilds[message.guild.id].voiceChannel != null) {
  120.         const voiceChannel = message.member.voiceChannel
  121.         const permissions = voiceChannel.permissionsFor(message.client.user)
  122.         if (!permissions.has('CONNECT')) return message.channel.send({embed: {description: "🛑 I don't have permission to CONNECT! Give me some."}});
  123.         if (!permissions.has('SPEAK')) return message.channel.send({embed: {description: "🛑 I don't have permission to SPEAK! Give me some."}});
  124.          if (args.length == 0 || !args) return message.channel.send(`:musical_note: ❯ m-play **Youtube URL / Search**`)
  125.             if (guilds[message.guild.id].queue.length > 0 || guilds[message.guild.id].isPlaying) {
  126.                 if(guilds[message.guild.id].queue.length > 100) return message.channel.send(``, {embed: {
  127.                     description: `🔒 Sorry, max queue length is 100, do **${prefix}clear** to clear entire queue or **${prefix}clear <number>** to clear 1 item`
  128.                 }})
  129.                 if (args.match(/^.*(youtu.be\/|list=)([^#\&\?]*).*/)) {
  130.                     const playlist = await youtube.getPlaylist(args);
  131.                     const videos = await playlist.getVideos();
  132.                     const queuesync = 100 - guilds[message.guild.id].queue.length
  133.                     if(queuesync < 0 || queuesync == 0) return message.channel.send(`:x: Cannot add this playlist, **\`\`MAX_QUEUE = 100\`\`** clear the current queue and try again!`)
  134.                     videos.slice(0, queuesync).forEach(video => {
  135.                         guilds[message.guild.id].isPlaying = true;
  136.                         guilds[message.guild.id].queueNames.push(video.title)
  137.                         guilds[message.guild.id].queue.push(video.id)
  138.                     })
  139.                     return message.channel.send(`[:musical_score: __${playlist.title}__] **${queuesync}** items Added to the **Queue**!`)                    ;
  140.                 }
  141.                 message.channel.send(`**${yt} Searching :mag_right: \`\`${args}\`\`**`).then(()=> {
  142.                 getID(args, function(id) {
  143.                    fetchVideoInfo(id, function(err, videoInfo) {
  144.                         if (err) throw new Error(err);
  145.                         if(videoInfo.duration > 1800) return message.channel.send(`**${message.author.username}, :x: Cannot play a video that's longer than 30 minutes**`).then(message.react(nope));
  146.                         else message.react(correct)
  147.                         add_to_queue(id, message);
  148.                         message.channel.send(new RichEmbed()
  149.                         .setAuthor("Added to queue", message.author.avatarURL)
  150.                         .setTitle(videoInfo.title)      
  151.                         .setURL(videoInfo.url)
  152.                         .addField("Channel", videoInfo.owner, true)
  153.                         .addField("Duration", convert.fromS(videoInfo.duration, 'mm:ss') , true)
  154.                         .addField("Published at", videoInfo.datePublished, true)
  155.                         .addField("Postion in queue", guilds[message.guild.id].queueNames.length, true)
  156.                         .setColor("RED")
  157.                         .setThumbnail(videoInfo.thumbnailUrl)
  158.                         )
  159.                         guilds[message.guild.id].queueNames.push(videoInfo.title);
  160.                     });
  161.                 })
  162.             })
  163.             } else {
  164.                 if (args.match(/^.*(youtu.be\/|list=)([^#\&\?]*).*/)) {
  165.                     const playlist = await youtube.getPlaylist(args);
  166.                     const videos = await playlist.getVideos();
  167.                     playMusic(videos[0].id, message)
  168.                     guilds[message.guild.id].queueNames.push(videos[0].title)
  169.                     guilds[message.guild.id].queue.push(videos[0].id)
  170.                     videos.slice(1, 100).forEach(video => {
  171.                         guilds[message.guild.id].isPlaying = true;
  172.                         guilds[message.guild.id].queueNames.push(video.title)
  173.                         guilds[message.guild.id].queue.push(video.id)
  174.                     })
  175.                     return message.channel.send(`[:musical_score: __${playlist.title}__] **${videos.slice(0, 100).length}** items Added to the **Queue**!\n**Playing :notes: \`\`${videos[0].title}\`\` - Now!**`)                    ;
  176.                 }
  177.                 message.channel.send(`${yt} **Searching :mag_right: \`\`${args}\`\` **`).then(() => {
  178.                 getID(args, function(id) {
  179.                     fetchVideoInfo(id, function(err, videoInfo) {
  180.                         if (err) throw new Error(err);
  181.                         if(videoInfo.duration > 1800) return message.channel.send(`**${message.author.username}, :x: Cannot play a video that's longer than 30 minutes**`).then(message.react(nope))
  182.                         else message.react(correct)
  183.                         playMusic(id, message);
  184.                         guilds[message.guild.id].isPlaying = true;
  185.                         guilds[message.guild.id].queue.push(id);
  186.                         guilds[message.guild.id].queueNames.push(videoInfo.title);
  187.                         message.channel.send(`**Playing :notes: \`\`${videoInfo.title}\`\` - Now!**`);
  188.                     });
  189.                 })})
  190.             }
  191.         } else {
  192.             message.reply(novc);
  193.         }
  194.  
  195.     } else if (mess.startsWith(prefix + "skip") || mess.startsWith(prefix+"عدي")) {
  196.         if(!message.member.voiceChannel) return message.reply(novc)
  197.         if(message.member.hasPermission('MANAGE_CHANNELS')) {
  198.         if (guilds[message.guild.id].queueNames[0]) {
  199.             message.channel.send(`**:fast_forward: Skipped** ${guilds[message.guild.id].queueNames[0]}`);
  200.             return skip_song(message);
  201.         } else return message.channel.send(`**:x: Nothing playing in this server**`);
  202.         }
  203.         else
  204.         if (guilds[message.guild.id].skippers.indexOf(message.author.id) === -1) {
  205.             guilds[message.guild.id].skippers.push(message.author.id);
  206.             guilds[message.guild.id].skipReq++;
  207.             if (guilds[message.guild.id].skipReq >= Math.ceil((guilds[message.guild.id].voiceChannel.members.size - 1) / 2)) {
  208.                 if (guilds[message.guild.id].queueNames[0]) {
  209.                 message.channel.send(`**:fast_forward: Skipped** ${guilds[message.guild.id].queueNames[0]}`);
  210.                 skip_song(message);
  211.                 } else return message.channel.send(`**:x: Nothing playing in this server**`);
  212.             } else {
  213.                 message.channel.send(`**:point_up::skin-tone-1: ${message.author.username} has vote to skip current song! **` + Math.ceil((guilds[message.guild.id].voiceChannel.members.size - 1) / 2) - guilds[message.guild.id].skipReq) + "**  more votes to skip! **";
  214.             }
  215.         } else {
  216.             message.reply("<:MxNo:449703922190385153> you already voted to skip!");
  217.         }
  218.  
  219.     } else if (mess.startsWith(prefix + "queue") || mess.startsWith(prefix+"قائمة")) {
  220.         if(guilds[message.guild.id].queueNames.length < 1) return message.channel.send(`**:x: Nothing playing in this server**`);
  221.         if(!guilds[message.guild.id].queueNames[1]) return message.channel.send('', {embed: {
  222.         description: `__Now Playing:__\n**[${guilds[message.guild.id].queueNames[0]}](https://www.youtube.com/watch?v=${guilds[message.guild.id].queue[0]})**`,
  223.         author: {
  224.         name: `${message.guild.name}'s Queue.`,
  225.         icon_url: message.guild.iconURL
  226.         },
  227.         color: 3447003
  228.         }});
  229.         else {
  230.             let x;
  231.             if(args > 1) {
  232.              x = Math.floor(args)*10+1
  233.             } else {
  234.               x = Math.floor(11)
  235.             }
  236.             let i;
  237.             if(args > 1) {
  238.                 i = x-11
  239.                } else {
  240.                  i = 0
  241.                }
  242.             let queuelist = guilds[message.guild.id].queueNames.slice(x-10,x).map(song => `**\`\`${++i}.\`\`** [${song}](https://www.youtube.com/watch?v=${guilds[message.guild.id].queue[i]})`).join('\n\n')
  243.             if(!queuelist) return message.channel.send(`<:MxNo:449703922190385153> | Page doesn't exist!`)
  244.             return message.channel.send('', {embed: {
  245.                 description: `__Now Playing:__\n**[${guilds[message.guild.id].queueNames[0]}](https://www.youtube.com/watch?v=${guilds[message.guild.id].queue[0]})**\n\n:arrow_down: __Up Next__  :arrow_down:\n\n${queuelist}\n\n**Total items in queue: ${guilds[message.guild.id].queueNames.length} | Page ${Math.floor(x/10)} of ${Math.floor((guilds[message.guild.id].queue.slice(1).length+10) /10)}**`,
  246.                 thumbnail: {url: "https://upload.wikimedia.org/wikipedia/commons/7/73/YouTube_Music.png"} ,
  247.                 author: {
  248.                     name: `${message.guild.name}'s Queue.`,
  249.                     icon_url: message.guild.iconURL
  250.                     },
  251.                 color: 3447003
  252.             }})
  253.         }
  254.     }
  255.  
  256. if(mess.startsWith(prefix+"np")) {
  257.     const short = require('short-number');
  258.     if(!guilds[message.guild.id].queue[0] || !guilds[message.guild.id].isPlaying) return message.channel.send(`**:x: Nothing playing in this server.**`)
  259.     await message.channel.startTyping()
  260.     await fetchVideoInfo(guilds[message.guild.id].queue[0], function(err, videoInfo) {
  261.                         if (err) throw new Error(err);
  262.                         message.channel.stopTyping(true);
  263.                         message.channel.send(new RichEmbed()
  264.                         .setTitle(videoInfo.title)      
  265.                         .setURL(videoInfo.url)
  266.                         .addField("Channel", `[**${videoInfo.owner}**](https://youtube.com/channel/${videoInfo.channelId})`, true)
  267.                         .addField("Duration", `${convert.fromS(videoInfo.duration, 'mm:ss')} — [**Download MP3**](https://www.flvto.biz/sa/downloads/mp3/yt_${videoInfo.videoId})`, true)
  268.                         .addField("Views", short(videoInfo.views), true)
  269.                         .addField("Likes/Dislikes", `👍 **${short(videoInfo.likeCount)}** / 👎 **${short(videoInfo.dislikeCount)}**`, true)
  270.                         .setColor("RED")
  271.                         .setImage(videoInfo.thumbnailUrl)
  272.                         )
  273.     })
  274. }
  275.  
  276. if(mess.startsWith(prefix+"stop") || mess.startsWith(prefix+"اطلع")) {
  277.     if (!message.member.voiceChannel) return message.reply(novc);
  278.     if(guilds[message.guild.id].isPlaying) guilds[message.guild.id].dispatcher.end();
  279.     if (guilds[message.guild.id].voiceChannel)
  280.     {
  281.     await clear()
  282.     message.guild.voiceConnection.disconnect();
  283.     message.channel.send(`**:mailbox_with_no_mail: Successfully disconnected!**`)
  284.     }
  285. }
  286.  
  287. if(mess.startsWith(prefix+"stfu") || message.content.startsWith(`<@${client.user.id}> stfu`)) {
  288.     if (!message.member.voiceChannel) return message.reply(novc);
  289.     if(guilds[message.guild.id].isPlaying) guilds[message.guild.id].dispatcher.end();
  290.     if (guilds[message.guild.id].voiceChannel)
  291.     {
  292.     await clear()
  293.     message.guild.voiceConnection.disconnect();
  294.     message.channel.send(`:cry: k sempai!`)
  295.     }
  296. }
  297.  
  298. if(message.content.startsWith(prefix+"search")) {
  299.     let index = 0
  300.     if(!args) return message.channel.send(`**${prefix}search [song name]**`)
  301.     const videos = await youtube.searchVideos(args, 10)
  302.     message.channel.send(`**<:MxYT:451042476552355841> Search Results for \`\`${args}\`\`**`,{embed: {
  303.     description: videos.map(song =>`**[${++index}]** [${song.title}](${song.url})`).join('\n'),
  304.     author: {
  305.     icon_url: message.author.avatarURL,
  306.     name: `${message.author.username} (${message.author.id})`  
  307.     },
  308.     footer: {
  309.         text: `Type a num between 1 and ${videos.length}, type cancel to cancel.`,
  310.     }
  311.     }})
  312. try {
  313. var response = await message.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11 || msg2.content === 'cancel' && msg2.author.id === message.author.id, {
  314.     maxMatches: 1,
  315.     time: 30000,
  316.     errors: ['time'],
  317. });
  318. } catch (error) {
  319. return message.channel.send(`**:x: Timeout**`)
  320. }
  321. if(guilds[message.guild.id].queue.length > 100) return message.channel.send(``, {embed: {
  322.     description: `🔒 Sorry, max queue length is 100, do **${prefix}clear** to clear entire queue or **${prefix}clear <number>** to clear 1 item`
  323. }})
  324. if(response.first().content === 'cancel') return message.channel.send(`**Cancelled it for yah :wink:**`)
  325. const videoIndex = parseInt(response.first().content)
  326. const voiceChannel = message.member.voiceChannel
  327. const permissions = voiceChannel.permissionsFor(message.client.user)
  328. if (!permissions.has('CONNECT')) return message.channel.send({embed: {description: "🛑 I don't have permission to CONNECT! Give me some."}});
  329. if (!permissions.has('SPEAK')) return message.channel.send({embed: {description: "🛑 I don't have permission to SPEAK! Give me some."}});    
  330. const id = videos[videoIndex - 1].id;
  331. message.delete();
  332. if(!guilds[message.guild.id].queue[0] || !guilds[message.guild.id].isPlaying) {
  333. fetchVideoInfo(id, function(err, videoInfo) {
  334. if (err) throw new Error(err);
  335. if(videoInfo.duration > 1800) return message.channel.send(`**${message.author.username}, :x: Cannot play a video that's longer than 30 minutes**`).then(message.react(nope));
  336. else message.react(correct)
  337. playMusic(id, message);
  338. guilds[message.guild.id].isPlaying = true;
  339. guilds[message.guild.id].queue.push(id);
  340. guilds[message.guild.id].queueNames.push(videos[videoIndex - 1].title);
  341. message.channel.send(`**Playing :notes: \`\`${videos[videoIndex - 1].title}\`\` - Now!**`);
  342. });
  343. } else {
  344.         fetchVideoInfo(`${id}`, function(err, videoInfo) {
  345.             if (err) throw new Error(err);
  346.             if(videoInfo.duration > 1800) return message.channel.send(`**${message.author.username}, :x: Cannot play a video that's longer than 30 minutes**`).then(message.react(nope));
  347.             else message.react(correct)
  348.             add_to_queue(id, message);
  349.             message.channel.send(new RichEmbed()
  350.             .setAuthor("Added to queue", message.author.avatarURL)
  351.             .setTitle(videoInfo.title)
  352.             .setURL(videoInfo.url)
  353.             .addField("Channel", videoInfo.owner, true)
  354.             .addField("Duration", convert.fromS(videoInfo.duration, 'mm:ss') , true)
  355.             .addField("Published at", videoInfo.datePublished, true)
  356.             .addField("Postion in queue", guilds[message.guild.id].queueNames.length, true)
  357.             .setColor("RED")
  358.             .setThumbnail(videoInfo.thumbnailUrl)
  359.             )
  360.             guilds[message.guild.id].queueNames.push(videoInfo.title);
  361.         });
  362. }
  363.     }
  364.  
  365.  
  366. else if (message.content.startsWith(prefix + 'vol') || mess.startsWith(prefix+"صوت")) {
  367.     if (!message.member.voiceChannel) return message.reply(novc);
  368.     if (!guilds[message.guild.id].isPlaying) return message.channel.send("**:x: Nothing playing in this server**")
  369.     if(!args) return message.channel.send(`**:loud_sound: Current Volume:** ${guilds[message.guild.id].dispatcher.volume*100}`)
  370.     if(isNaN(args)) return message.channel.send(`**:x: Volume must be a number -_-**`)
  371.     if (args > 200) return message.reply('**:headphones: For some health reasons the max vol you can use is ``200``, kthx**');
  372.     if (args < 1) return message.reply("**:headphones: you can set volume from ``1`` to ``200``**");
  373.     guilds[message.guild.id].dispatcher.setVolume((0.01 * parseInt(args)))
  374.     guilds[message.guild.id].volume = 0.01 * parseInt(args)
  375.     message.channel.send(`**:loud_sound: Volume:** ${guilds[message.guild.id].dispatcher.volume*100}`);
  376. }
  377.  
  378.  
  379. else if (mess.startsWith(prefix + 'pause') || mess.startsWith(prefix+"وقف")) {
  380.     if (!message.member.voiceChannel) return message.reply(novc);
  381.     if (guilds[message.guild.id].dispatcher.paused === true) return message.channel.send("*:hash: Already paused*")
  382.     message.channel.send(':pause_button: **Paused**').then(() => {
  383.         guilds[message.guild.id].dispatcher.pause();
  384.     });
  385. }
  386.  
  387. else if (mess.startsWith(prefix + 'resume') || mess.startsWith(prefix+"كمل")) {
  388.     if (!message.member.voiceChannel) return message.reply(novc);
  389.     if (guilds[message.guild.id].dispatcher.paused === false) return message.channel.send("*:hash: Nothing to resume.*")
  390.     message.channel.send(':play_pause: **Resuming**').then(() => {
  391.         guilds[message.guild.id].dispatcher.resume();
  392.     });
  393. }
  394.  
  395.  
  396. // ONE ITEM WORKS, BUT QUEUE NO... ==> QUEUE LOOP SYSTEM IN 2.0
  397.  
  398. else if (mess.startsWith(prefix + 'loop') || mess.startsWith(prefix+"عيد")) {
  399.     if (!message.member.voiceChannel) return message.reply(novc);
  400.     if (!guilds[message.guild.id].isPlaying) return message.channel.send("**:x: Nothing playing in this server**")
  401.     if(guilds[message.guild.id].loop === true) {
  402.         message.channel.send(`:arrow_right_hook: **Looping Disabled**`)
  403.         guilds[message.guild.id].loop = false;        
  404.         return;
  405.     } else if(guilds[message.guild.id].loop === false) {
  406.     guilds[message.guild.id].loop = true;
  407.     message.channel.send(':repeat_one: **Looping Enabled!**')
  408.     return;
  409.     }
  410. }
  411.  
  412.  
  413. else if (mess.startsWith(prefix + 'join') || mess.startsWith(prefix+"ادخل")) {
  414.     if (!message.member.voiceChannel) return message.reply(novc);
  415.     if(!guilds[message.guild.id].isPlaying && guilds[message.guild.id].queueNames.length <= 0) {
  416.         message.member.voiceChannel.join().then(message.react(correct));
  417.         message.channel.send(`**:page_facing_up: Queue moved to \`\`${message.member.voiceChannel.name}\`\`**`)
  418.     } else {
  419.         message.channel.send(`<:MxNo:449703922190385153> **Music is being played in another voice channel!**`)
  420.     }
  421. }
  422.  
  423. else if (mess.startsWith(prefix + 'clear') || mess.startsWith(prefix+"نظف")) {
  424.     if (!message.member.voiceChannel) return message.reply(novc);
  425.     if(!guilds[message.guild.id].queueNames[0] || !guilds[message.guild.id].isPlaying) return message.channel.send(`**:x: Nothing playing in this server**`)
  426.    if(guilds[message.guild.id].queueNames.length > 1) {
  427.     if(!args || isNaN(args) && args != 0) {
  428.     guilds[message.guild.id].queueNames.splice(1, guilds[message.guild.id].queueNames.length)
  429.     guilds[message.guild.id].queue.splice(1, guilds[message.guild.id].queue.length)
  430.     message.channel.send(`:asterisk: Cleared the queue of **${message.guild.name}**`)
  431.     } else if(args > 0) {
  432.         const removedsong = guilds[message.guild.id].queueNames[parseInt(args)]
  433.         if(!removedsong) return message.channel.send(`:x: **No such item, or item doesn't exist!**`)
  434.         guilds[message.guild.id].queueNames.splice(parseInt(args), 1)
  435.         guilds[message.guild.id].queue.splice(parseInt(args), 1)
  436.         return message.channel.send(`:wastebasket: Removed **${removedsong}** from the queue.`);}
  437.    } else if(guilds[message.guild.id].queueNames.length <= 1 ) {
  438.        message.channel.send(`<:MxNo:449703922190385153> There's only 1 item in the queue. use \`\`${prefix}skip\`\` instead! `)
  439.    }
  440. }
  441. });
  442.  
  443.  
  444.  
  445. //
  446. function skip_song(message) {
  447.     guilds[message.guild.id].dispatcher.end();
  448. }
  449.  
  450. //ERROR: Playing 1 item over and over.
  451. async function playMusic(id, message) {
  452.     guilds[message.guild.id].voiceChannel = message.member.voiceChannel;
  453.     guilds[message.guild.id].voiceChannel.join().then(function(connection) {
  454.         stream = ytdl("https://www.youtube.com/watch?v=" + id, {
  455.             filter: 'audioonly',
  456.             quality: 'highestaudio',
  457.             audioEncoding: "opus"
  458.         });
  459.         guilds[message.guild.id].skipReq = 0;
  460.         guilds[message.guild.id].skippers = [];
  461.         guilds[message.guild.id].dispatcher = connection.playStream(stream, {bitrate: "auto", volume: guilds[message.guild.id].volume});
  462.         guilds[message.guild.id].dispatcher.on('end', async function() {
  463.             guilds[message.guild.id].skipReq = 0;
  464.             guilds[message.guild.id].skippers = [];
  465.            if(guilds[message.guild.id].loop === true) return playMusic(guilds[message.guild.id].queue[0], message)
  466.            else                      
  467.            await guilds[message.guild.id].queue.shift();
  468.            await guilds[message.guild.id].queueNames.shift();
  469.             if (guilds[message.guild.id].queue.length === 0) {
  470.                 guilds[message.guild.id].queue = [];          
  471.                 guilds[message.guild.id].queueNames = [];
  472.                 guilds[message.guild.id].isPlaying = false;
  473.                 setTimeout(function() {
  474.                 if(guilds[message.guild.id].voiceChannel !== null) return message.channel.send(`**:stop_button: Queue concluded.**`)
  475.             }, 1000)
  476.             } else {
  477.                 setTimeout(async function() {
  478.                     if(!guilds[message.guild.id].queueNames || guilds[message.guild.id].queueNames[0] == undefined) return;
  479.                     await playMusic(guilds[message.guild.id].queue[0], message);
  480.                    message.channel.send(`**Playing :notes: \`\`${guilds[message.guild.id].queueNames[0]}\`\` - Now!**`)
  481.                 }, 500);
  482.             }
  483.         });
  484.     });
  485. }
  486.  
  487.  
  488.  
  489. function getID(str, cb) {
  490.     if (isYoutube(str)) {
  491.          cb(getYouTubeID(str));
  492.     } else {
  493.         search_video(str, function(id) {
  494.             cb(id);
  495.         });
  496.     }
  497. }
  498.  
  499. function add_to_queue(strID, message) {
  500.     if (isYoutube(strID)) {
  501.         guilds[message.guild.id].queue.push(getYouTubeID(strID));
  502.     } else {
  503.         guilds[message.guild.id].queue.push(strID);
  504.     }
  505. }
  506.  
  507. function search_video(query, callback) {
  508.     request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
  509.         var json = JSON.parse(body);
  510.         if (!json.items[0]) callback("3_-a9nVZYjk");
  511.         else {
  512.             callback(json.items[0].id.videoId);
  513.         }
  514.     });
  515. }
  516.  
  517. function isYoutube(str) {
  518.     return str.toLowerCase().indexOf("youtube.com") > -1 || str.toLowerCase().indexOf("youtu.be") > -1;
  519. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top