0

I have subfolders for each of my commands and I'm wondering how I would check the name of the command's folder without having to add code into the command file itself. I've tried folders.filter(folder => folder.includes(command) and I'm hoping there's a similar way that could help me.

const folders = fs.readdirSync(`./categories`);

for (const folder of folders) {
    const files = fs.readdirSync(`./categories/${folder}`);
    for (const file of files) {
        const command = require(`./categories/${folder}/${file}`);
        client.commands.set(command.name, command);
    };
};

client.on("message", async message => {
    if (command.args && !args.length) {
        const commandArgs = new Discord.MessageEmbed()
            .setAuthor(command.category) // HERE - how would i check what subfolder the given command is in?
            .setTitle(command.name)
            .setDescription(command.description);
   }

   //code...
});

1 Answer 1

1

You can simply add a property when retrieving it:

const command = require(`./categories/${folder}/${file}`);
command.folder = folder;

client.commands.set(command.name, command);

Now you can use it when referencing the object:

const commandArgs = new Discord.MessageEmbed()
    .setTitle("From folder: " + command.folder);
Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much i was trying to figure that out for like a day lmao

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.