首页 > 解决方案 > 错误:ENOENT:没有这样的文件或目录,scandir './slash_commands'

问题描述

我真的坚持这一点,我已经有 V13 代码,我想添加我有的斜杠命令,但由于某种原因我无法通过这个,我找不到任何解释该做什么的东西。

如果有人可以帮我解决这个问题,将不胜感激。

code: const { readdirSync } = require("fs"),
ascii = require("ascii-table");

let table = new ascii("Commands");
table.setHeading("Slash Commands", "Load status");

module.exports = (client) => {
        readdirSync("./slash_commands").forEach(dir => {
            const commands = readdirSync(`./slash_commands/${dir}/`).filter(file => file.endsWith(".js"));
    
            for (let file of commands) {
                let pull = require(`../slash_commands/${dir}/${file}`);

                client.slash_commands.set(pull.data.name, pull);
                table.addRow(file, '✅');
            
                if (pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach(alias => client.aliases.set(alias, pull.name));
            }
        });
        // Log the table
        console.log(table.toString());
}

输出:

 Error: ENOENT: no such file or directory, scandir './slash_commands'
    at readdirSync (node:fs:1390:3)
    at module.exports (C:\Users\codiene wrld\Desktop\dream\handlers\slash_command.js:8:9)
    at Object.<anonymous> (C:\Users\codiene wrld\Desktop\dream\index.js:11:99)

标签: javascriptdiscord.js

解决方案


推荐阅读