Home > Blockchain >  I want To make command sub folders . But my bot doesnt read commands inside the folders . There is n
I want To make command sub folders . But my bot doesnt read commands inside the folders . There is n

Time:06-30

const fs = require('node:fs'); const Discord = require('discord.js')

module.exports = (client) => {
    
client.commands = new Discord.Collection();
const commandFolders = fs.readdirSync('./commands')

const commands = [];
for (const folder of commandFolders) {
    const command_files = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
    for (const file of command_files) {
        const command = require(`../commands/${folder}/${file}`);
        client.commands.set(command.name, command);

        
    }
}

}

CodePudding user response:

You need to adapt your readdirSync arguments

const command_files = fs.readdirSync('./commands/'   folder);

This will give you all your files. Then you need to:

for (const file of command_files) {
    const command = require('./commands/'   folder   '/'   file);
    client.commands.set(command.name, command);        
}

CodePudding user response:

const command_files = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
  • Related