Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda