From 7c9e65b3d3d65143ec4080bcfc5aa9c0b9e4a970 Mon Sep 17 00:00:00 2001 From: Vachan MN Date: Thu, 4 Nov 2021 20:53:48 +0530 Subject: [PATCH] Now Playing Command and bug fixes --- commands/music/nowplaying.js | 50 +++++++++++++++++++++++++++++++++ events/distubeEvents/addList.js | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 commands/music/nowplaying.js diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js new file mode 100644 index 0000000..255d975 --- /dev/null +++ b/commands/music/nowplaying.js @@ -0,0 +1,50 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "nowplaying", + description: "Find out which song is currently playing", + category: "music", + usage: "nowplaying", + guildOnly: true, + aliases: ["np"], + /** + * @description Executes when the command is called by command handler. + * @author Vachan MN + * @param {Object} message The Message Object of the command. + * @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself. + */ + + async execute(message, args) { + const serverQueue = message.client.distube.getQueue(message) + if (!serverQueue) return message.channel.send("There is nothing playing."); + await message.channel.sendTyping(); + const progressProportion = (serverQueue.currentTime / serverQueue.songs[0].duration)*10; + const progressBar = "▰".repeat(Number(progressProportion.toFixed(0))) + "▱".repeat(10-Number(progressProportion.toFixed(0))); + const volume = (serverQueue.volume > 100)? 100 : serverQueue.volume; + const volumeProportion = (volume/100)*10; + const volumeBar = "▰".repeat(Number(volumeProportion.toFixed(0))) + "▱".repeat(10-volumeProportion.toFixed(0)); + const embed = new MessageEmbed() + .setColor("#0099ff") + .setTitle(`Now Playing(${serverQueue.songs.indexOf(serverQueue.songs[0]) + 1}/${serverQueue.songs.length})`) + .setDescription(`[**${serverQueue.songs[0].name}**](${serverQueue.songs[0].url})`) + .addField("Duration:", `${serverQueue.formattedCurrentTime}/${serverQueue.songs[0].formattedDuration} \n${progressBar}`, true) + .addField("volume:", `${serverQueue.volume}/100 \n${volumeBar}`, true) + .setThumbnail(serverQueue.songs[0].thumbnail) + .setFooter(`Requested by ${serverQueue.songs[0].user.username}#${serverQueue.songs[0].user.discriminator}`); + if(serverQueue.filters.length > 0) embed.addField("Filters", `${serverQueue.filters}`, true); + switch(serverQueue.repeatMode) { + case 0: + break; + case 1: + embed.addField("Repeat Mode:", "Repeating the current song", true); + break; + case 2: + embed.addField("Repeat Mode:", "Repeating all songs in the queue", true); + break; + } + if (serverQueue.paused) embed.addField("Paused:", "Yes", true); + if (serverQueue.voiceChannel && args[0]==="dev") embed.addField("Voice Channel Name:", serverQueue.voiceChannel.name, true); + if (serverQueue.voiceChannel && args[0]==="dev") embed.addField("Current Channel Bitrate:", `${serverQueue.voiceChannel.bitrate/1000}kbps`, true); + message.channel.send({embeds: [embed]}); + }, +}; diff --git a/events/distubeEvents/addList.js b/events/distubeEvents/addList.js index 751a492..08f10a2 100644 --- a/events/distubeEvents/addList.js +++ b/events/distubeEvents/addList.js @@ -20,7 +20,7 @@ const { MessageEmbed } = require('discord.js'); .setColor('#0099ff') .setTitle(`Added playlist [${playlist.name}](${playlist.url})`) .setDescription(`${playlist.tracks.length} tracks added`) - .addField('Number of songs', playlist.songs.length) + .addField('Number of songs in queue:', `queue.songs.length`) .setFooter(`Added by ${playlist.owner}`) .setTimestamp(); queue.textChannel.send({ embeds: [embed] });