diff --git a/bot.js b/bot.js index 41c6cdc..c4957ce 100644 --- a/bot.js +++ b/bot.js @@ -10,7 +10,7 @@ const fs = require("fs"); const { Client, Collection, Intents } = require("discord.js"); const { REST } = require("@discordjs/rest"); const { Routes } = require("discord-api-types/v9"); -const { token, client_id, test_guild_id } = require("./config.json"); +const { token, client_id, test_guild_id, owner } = require("./config.json"); const DisTube = require('distube') const SoundCloudPlugin = require('@distube/soundcloud') const SpotifyPlugin = require('@distube/spotify') @@ -54,6 +54,8 @@ for (const file of eventFiles) { // Define Collection of Commands, Slash Commands and cooldowns client.commands = new Collection(); +client.version = "v1.0.0" +client.ownerID = owner client.slashCommands = new Collection(); client.buttonCommands = new Collection(); client.selectCommands = new Collection(); @@ -69,8 +71,6 @@ client.distube = new DisTube.default(client, { leaveOnStop: false, plugins: [new SoundCloudPlugin.default(), new SpotifyPlugin.default()], ytdlOptions: { - quality: "highestaudio", - filter: "audioonly", quality: "highestaudio", audioBitrate: 240000, @@ -94,7 +94,7 @@ const commandFolders = fs.readdirSync("./commands"); // Loop through all files and store commands in commands collection. for (const folder of commandFolders) { - if (folder==".DS_Store") {continue;} + if (folder===".DS_Store") {continue;} const commandFiles = fs .readdirSync(`./commands/${folder}`) .filter((file) => file.endsWith(".js")); @@ -140,12 +140,12 @@ const contextMenus = fs.readdirSync("./interactions/context-menus"); // Loop through all files and store slash-commands in slashCommands collection. for (const folder of contextMenus) { - if (folder==".DS_Store") {continue;} + if (folder===".DS_Store") {continue;} const files = fs .readdirSync(`./interactions/context-menus/${folder}`) .filter((file) => file.endsWith(".js")); for (const file of files) { - if (folder==".DS_Store") {continue;} + if (folder===".DS_Store") {continue;} const menu = require(`./interactions/context-menus/${folder}/${file}`); const keyName = `${folder.toUpperCase()} ${menu.data.name}`; client.contextCommands.set(keyName, menu); @@ -260,7 +260,7 @@ const distubeEventFiles = fs .filter((file) => file.endsWith(".js")); // Loop through all files and execute the event when it is actually emmited. -const status = queue => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filters.join(", ") || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode === 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\`` +// const status = queue => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filters.join(", ") || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode === 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\`` for (const file of distubeEventFiles) { const event = require(`./events/distubeEvents/${file}`); if (event) { diff --git a/commands/misc/help.js b/commands/misc/help.js index 6037675..5e8f9fe 100644 --- a/commands/misc/help.js +++ b/commands/misc/help.js @@ -14,8 +14,9 @@ module.exports = { name: "help", description: "List all commands of bot or info about a specific command.", aliases: ["commands"], - usage: "[command name]", + usage: "help ", cooldown: 5, + category: "misc", /** * @description Executes when the command is called by command handler. @@ -24,105 +25,65 @@ module.exports = { * @param {String[]} args The Message Content of the received message seperated by spaces (' ') in an array, this excludes prefix and command/alias itself. */ - execute(message, args) { - const { commands } = message.client; - - // If there are no args, it means it needs whole help command. - - if (!args.length) { - /** - * @type {Object} - * @description Help command embed object - */ - - let helpEmbed = new MessageEmbed() - .setColor(0x4286f4) - .setURL(process.env.URL) - .setTitle("List of all my commands") - .setDescription( - "`" + commands.map((command) => command.name).join("`, `") + "`" - ) - - .addField( - "Usage", - `\nYou can send \`${prefix}help [command name]\` to get info on a specific command!` - ); - - // Attempts to send embed in DMs. - - return message.author - .send({ embeds: [helpEmbed] }) - - .then(() => { - if (message.channel.type === "dm") return; - - // On validation, reply back. - - message.reply({ - content: "I've sent you a DM with all my commands!", - }); - }) - .catch((error) => { - // On failing, throw error. - - console.error( - `Could not send help DM to ${message.author.tag}.\n`, - error - ); - - message.reply({ content: "It seems like I can't DM you!" }); - }); - } - - // If argument is provided, check if it's a command. - - /** - * @type {String} - * @description First argument in lower case - */ - - const name = args[0].toLowerCase(); - - /** - * @type {Object} - * @description The command object - */ - - const command = - commands.get(name) || - commands.find((c) => c.aliases && c.aliases.includes(name)); - - // If it's an invalid command. - - if (!command) { - return message.reply({ content: "That's not a valid command!" }); - } - - /** - * @type {Object} - * @description Embed of Help command for a specific command. - */ - - let commandEmbed = new MessageEmbed() - .setColor(0x4286f4) - .setTitle("Command Help"); - - if (command.description) - commandEmbed.setDescription(`${command.description}`); - - if (command.aliases) - commandEmbed - .addField("Aliases", `\`${command.aliases.join(", ")}\``, true) - .addField("Cooldown", `${command.cooldown || 3} second(s)`, true); - if (command.usage) - commandEmbed.addField( - "Usage", - `\`${prefix}${command.name} ${command.usage}\``, - true - ); - - // Finally send the embed. - - message.channel.send({ embeds: [commandEmbed] }); + async execute(message, args) { + // Get a lost of all commands + const commands = message.client.commands; + const commands_json = JSON.parse(JSON.stringify(commands)); + const categories = []; + for(const command of commands_json) { + if(!categories.includes(command["category"])) { + categories.push(command["category"]); + } + } + if (String(message.author.id) !== message.client.ownerID) { + categories.splice(categories.indexOf('owner'), 1); + } + // If no args then send categories list + if (args.length === 0) { + const embed = new MessageEmbed() + .setColor(0x00ffff) + .setTitle(`${message.client.user?.tag} Help`) + .setDescription(`Use \`${prefix}help \` for more info on a command.`) + .setFooter(`${message.client.user?.tag} ${message.client.version}`); + for(const category of categories) { + embed.addField(category, commands.filter(command => command["category"] == category).map(command => `\`${command["name"]}\``).join(", ")); + } + message.channel.send({ embeds: [embed]}); + // If category name is arg then send commands in that category + } else if(categories.includes(args[0])) { + const embed = new MessageEmbed() + .setColor(0x00ffff) + .setTitle(`${message.client.user?.tag} Help`) + .setDescription(`Use \`${prefix}help \` for more info on a command.`) + .setFooter(`${message.client.user?.tag} v${message.client.version}`); + for(const command of commands_json) { + if(command["category"] == args[0]) { + embed.addField(command["name"], command["description"]); + } + } + message.channel.send({ embeds: [embed]}); + // If command name is arg then send command info + } else if(commands.find(commands => commands["name"] == args[0])) { + try { + const embed = new MessageEmbed() + .setColor(0x00ffff) + .setTitle(`${message.client.user?.tag} Help`) + .setDescription(`Use \`${prefix}help \` for more info on a command.`) + .setFooter(`${message.client.user?.tag} v${message.client.version}`); + const command = commands.find(command => command["name"] == args[0]); + embed.addField("Description", command["description"]); + embed.addField("Usage", command["usage"]); + if(command["aliases"]) embed.addField("Aliases", command["aliases"].join(", ")); + message.channel.send({ embeds: [embed]}); + } catch(e) { + console.log(e); + // Error occurs send an error message + message.channel.send(`\`${args[0]}\` is not a valid command or category`); + } + } + // If args is present but its neither command or category, send error message + else { + message.channel.send(`\`${args[0]}\` is not a valid command or category`); + } }, }; diff --git a/commands/misc/ping.js b/commands/misc/ping.js index 4905a54..932908d 100644 --- a/commands/misc/ping.js +++ b/commands/misc/ping.js @@ -1,3 +1,5 @@ +const {MessageEmbed} = require('discord.js'); + /** * @file Sample ping command * @author Naman Vrati @@ -6,6 +8,8 @@ module.exports = { name: "ping", + description: "Pong!", + category: "misc", /** You need to uncomment below properties if you need them. */ //description: 'Ping!', @@ -21,6 +25,12 @@ module.exports = { */ execute(message, args) { - message.channel.send({ content: "Pong." }); + embed = new MessageEmbed() + .setColor('#0099ff') + .setTitle('Pong!') + .setDescription(`🏓Latency is ${Date.now() - message.createdTimestamp}ms.`) + .addField("API Latency", `${message.client.ws.ping}ms`, true) + .setTimestamp(); + message.channel.send({ embeds: [embed] }); }, }; diff --git a/commands/misc/reload.js b/commands/misc/reload.js index b3f83bd..e045f1e 100644 --- a/commands/misc/reload.js +++ b/commands/misc/reload.js @@ -12,6 +12,7 @@ module.exports = { description: "Reloads a command", args: true, ownerOnly: true, + category: "owner", /** * @description Executes when the command is called by command handler. diff --git a/commands/music/autoplay.js b/commands/music/autoplay.js index f02933d..065aed8 100644 --- a/commands/music/autoplay.js +++ b/commands/music/autoplay.js @@ -1,6 +1,7 @@ module.exports = { name: "autoplay", description: "Turn on/off Autoplay", + category: "music", usage: "autoplay", guildOnly: true, /** diff --git a/commands/music/filters.js b/commands/music/filters.js index e2d5e88..05ad975 100644 --- a/commands/music/filters.js +++ b/commands/music/filters.js @@ -3,6 +3,7 @@ module.exports = { description: "Add filters to the playing song", usage: "filters ", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/pause.js b/commands/music/pause.js index 243b80e..4bc2749 100644 --- a/commands/music/pause.js +++ b/commands/music/pause.js @@ -5,6 +5,7 @@ module.exports = { description: "pause the playing song", usage: "pause", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/play.js b/commands/music/play.js index 5407161..1142e60 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -5,6 +5,7 @@ module.exports = { description: "Play a song", usage: "play ", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. diff --git a/commands/music/previous.js b/commands/music/previous.js index bbe8fbf..15c0d7b 100644 --- a/commands/music/previous.js +++ b/commands/music/previous.js @@ -3,6 +3,7 @@ module.exports = { description: "Plays the previous song", usage: "previous", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/queue.js b/commands/music/queue.js index 31fa949..d8d1438 100644 --- a/commands/music/queue.js +++ b/commands/music/queue.js @@ -5,6 +5,7 @@ module.exports = { description: "show the queue", usage: "queue", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/repeat.js b/commands/music/repeat.js index 40f30b3..334034e 100644 --- a/commands/music/repeat.js +++ b/commands/music/repeat.js @@ -4,6 +4,7 @@ module.exports = { usage: "repeat ", guildOnly: true, aliases: ["loop"], + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/resume.js b/commands/music/resume.js index ab281d3..ea747b5 100644 --- a/commands/music/resume.js +++ b/commands/music/resume.js @@ -3,6 +3,7 @@ module.exports = { description: "Resume the paused song", usage: "resume", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/seek.js b/commands/music/seek.js index 7e4ef68..cccaa6b 100644 --- a/commands/music/seek.js +++ b/commands/music/seek.js @@ -3,6 +3,7 @@ module.exports = { description: "seek to a position in the playing song", usage: "seek ", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/skip.js b/commands/music/skip.js index 1239ff4..bed3627 100644 --- a/commands/music/skip.js +++ b/commands/music/skip.js @@ -3,6 +3,7 @@ module.exports = { description: "Skip the playing song", usage: "skip", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/stop.js b/commands/music/stop.js index e6fd58a..f9530ad 100644 --- a/commands/music/stop.js +++ b/commands/music/stop.js @@ -3,6 +3,7 @@ module.exports = { description: "Stop the playing song", usage: "stop", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN diff --git a/commands/music/volume.js b/commands/music/volume.js index deb3976..9ecfe07 100644 --- a/commands/music/volume.js +++ b/commands/music/volume.js @@ -3,6 +3,7 @@ module.exports = { description: "Set the volume of the player", usage: "volume ", guildOnly: true, + category: "music", /** * @description Executes when the command is called by command handler. * @author Vachan MN