diff --git a/commands/untils/passwordgen.js b/commands/untils/passwordgen.js index 32327e4..33aac70 100644 --- a/commands/untils/passwordgen.js +++ b/commands/untils/passwordgen.js @@ -4,6 +4,7 @@ var generator = require('generate-password'); module.exports = { name: "password-generator", description: "Generates a random secure password", + private: true, options: [{ "name": "length", "description": "Provide a number for how long to make the password.", diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 3bff457..a162b79 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -1,15 +1,51 @@ const client = require("../index"); +require("dotenv").config(); +const { glob } = require("glob"); +const { promisify } = require("util"); +const globPromise = promisify(glob); client.on("interactionCreate", async (interaction) => { + + // Slash Commands + const slashCommands = await globPromise(`${process.cwd()}/commands/*/*.js`); + const arrayOfSlashCommands = []; + slashCommands.map((value) => { + const file = require(value); + const splitted = value.split("/"); + const directory = splitted[splitted.length - 2]; + + if (!file?.name) return; + + const properties = { directory, ...file }; + client.slashCommands.set(file.name, properties); + + if (["MESSAGE", "USER"].includes(file.type)) delete file.description; + arrayOfSlashCommands.push(file); + }); + // Slash Command Handling if (interaction.isChatInputCommand()) { -console.log(interaction ) - if (interaction.commandName == "password-generator") { - await interaction.deferReply({ ephemeral: true }).catch(() => { }); + + let commandData = [] + await arrayOfSlashCommands.forEach(command => { + console.log(command.name) + if (command.name == interaction.commandName) { + commandData.push(command) + } + }); + + let dataToProcess = JSON.stringify(commandData[0]) + let parsedData = JSON.parse(dataToProcess) + + console.log(parsedData.private) + + if (parsedData.private == true) { + await interaction.deferReply({ ephemeral: true }).catch(() => { }); + } else { await interaction.deferReply({ ephemeral: false }).catch(() => { }); - } + const cmd = client.slashCommands.get(interaction.commandName); if (!cmd) return interaction.followUp({ content: "An error has occurred " }); @@ -35,4 +71,5 @@ console.log(interaction ) const command = client.slashCommands.get(interaction.commandName); if (command) command.run(client, interaction); } + }); diff --git a/handler/index.js b/handler/index.js index 3cff50e..7326525 100644 --- a/handler/index.js +++ b/handler/index.js @@ -30,6 +30,7 @@ module.exports = async (client) => { // // Register for a single guild // await client.guilds.cache.get("GUIDIDHERE").commands.set(arrayOfSlashCommands); + console.log(arrayOfSlashCommands) // Register for all the guilds the bot is in await client.application.commands.set(arrayOfSlashCommands); });