Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Discordjs v12 | cannot find module ../undefined/help.js

My bot has a command located in /commands/developer/reload.js and it's purpose is to unload a command then load it again. But when trying to find the commands folder it throws an error saying Cannot find module '../undefined/help.js' but the path is ../misc/help.js

Code:

const fs = require('fs');

module.exports = {
    name: 'reload',
    description: 'Reloads a command',
    args: true,
    usage: '<command_name>',
    cooldown: 1,
    aliases: ['rl', 'restart'],
    execute(message, args) {
        const commandName = args[0].toLowerCase();
        const command = message.client.commands.get(commandName) || message.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

        if(!command) {
            return message.channel.send(`There is no command called '${commandName}'`);
        }
        // commandFolders returns undefined
        const commandFolders = fs.readdirSync('./commands');
        // Also returns undefined
        const folderName = commandFolders.find(folder => {
            fs.readdirSync(`./commands/${folder}`).includes(`${command.name}.js`);
        })
        // Command errors out here
        delete require.cache[require.resolve(`../${folderName}/${command.name}.js`)];
        
        // This part never runs.
        try {
            const newCommand = require(`../${folderName}/${command.name}.js`);
            message.client.commands.set(newCommand.name, newCommand);
            message.channel.send(`Command '${newCommand.name}' was reload successfully`)
        } catch (err) {
            console.error(err);
            message.channel.send(`There was an error while reloading a Command.`)
        }
    }

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason why you are getting the folder as undefined is because you are not returning the folder you are trying to find in the folderName function. It is trying to find a folder with the command and even if it does, you are not doing anything with it, you are not returning it or logging it into the console. So you just have to return it, the folderName function might look something like this:

const folderName = commandFolders.find(folder => fs.readdirSync(`commands/${folder}`).includes(`${command.name}.js`)) // If you want a one-liner
// Or
const folderName = commandFolders.find(folder => {
    return fs.readdirSync(`commands/${folder}`).includes(`${command.name}.js`)
})

If the error persists, the error is most likely there because the path is not correct. So in that case, please provide the folder structure of your bot

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda