如何修复无法找到模块 '.functions/handleCommands.js' 错误?

How do I Fix a Cannot find module '.functions/handleCommands.js' error?

在安装命令和事件处理程序后运行让我的机器人登录时,我收到了错误

Error: Cannot find module '.functions/handleCommands.js'

Require stack:

C:\Users\levan\Desktop\Discordbot\Bot Templates command handling\src\bot.js

at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at C:\Users\levan\Desktop\Discordbot\Bot Templates command handling\src\bot.js:14:9
at Object.<anonymous> (C:\Users\levan\Desktop\Discordbot\Bot Templates command handling\src\bot.js:19:3)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12) {   code: 
'MODULE_NOT_FOUND',   
requireStack: [
'C:\Users\levan\Desktop\Discordbot\Bot Templates\2 command handling\src\bot.js'

在浏览了文件夹功能和 handleCommands.js 之后,我仍然无法弄清楚我遗漏了什么或者我可能搞砸了什么。我想也许我的 module.exports 放错了地方,但四处移动也没有解决问题。

const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = 'redacted'; // your bots token
const guildId = 'redacted'; // the server id the bot will be on

module.exports = (clinet) => {
    clinet.handleCommands = async (commandFolders, path) =>{
        clinet.commandArray = [];
        for(folder of commandFolders){
            const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
                for (const file of commandFiles) {
                    const command = require(`../commands/${folder}/${file}`);
                    // Set a new item in the Collection
                    // With the key as the command name and the value as the exported module
                    client.commands.set(command.data.name, command);
                    clinet.commandArray.push(command.data.toJSON());
            }
        }
        
    };
};

const rest = new REST({ version: '9' }).setToken(process.env.token);

(async () => {
    try {
        console.log('Started refreshing application (/) commands.');

        await rest.put(
            Routes.applicationGuildCommands(clientId, guildId),
            { body: clinet.commandArray },
        );

        console.log('Successfully reloaded application (/) commands.');
    } catch (error) {
        console.error(error);
    }
})();

由于错误是 MODULE_NOT_FOUND 我想也许我没有 运行 让我的机器人工作所需的所有安装。 运行通过我的 npm 列出错误仍然存​​在。

已安装 NPM

我的目标是让 Bot 重新上线,并弄清楚如何解决此类错误,以防它再次出现。如果您能提供任何帮助,我们将不胜感激。

'.functions/handleCommands.js' 应该是 './functions/handleCommands.js' 咖啡因不能代替睡眠