【发布时间】:2021-09-08 11:54:09
【问题描述】:
v13 机器人在读取命令/审核类别文件夹中的命令时遇到问题
我只是希望机器人能够识别并打开类别文件夹中的命令,以便更有条理
命令/审核
命令/乐趣
我的代码:
const commandFiles = fs.readdirSync("./src/Commands/*/*.js")
.filter(file => file.endsWith(".js"));
/**
* @type {Command[]}
*/
const commands = commandFiles.map(file => require(`../Commands/*/*/${file}`));
commands.forEach(cmd => {
console.log(`Command ${cmd.name} loaded`);
this.commands.set(cmd.name, cmd);
});
const slashCommands = commands
.filter(cmd => ["BOTH", "SLASH"].includes(cmd.type))
.map(cmd => ({
name: cmd.name.toLowerCase(),
description: cmd.description,
permissions: [],
options: cmd.slashCommandOptions,
defaultPermission: true
}));
错误:
node:internal/fs/utils:344
throw err;
^
Error: ENOENT: no such file or directory, scandir './src/Commands/*/*.js'
at Object.readdirSync (node:fs:1390:3)
at Client.start (C:\Users\stifler\Desktop\botv13\src\Structures\Client.js:31:27)
at Object.<anonymous> (C:\Users\stifler\Desktop\botv13\src\index.js:11:8)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47 {
errno: -4058,
syscall: 'scandir',
code: 'ENOENT',
path: './src/Commands/*/*.js'
}
【问题讨论】:
-
你真的替换了
*s吗? -
@MrMythical 我不明白你的问题
-
在您的文件夹名称中?
-
@MrMythical 我的文件夹名称正常。每个文件夹里面的Commands/Fun Commands/Economy都是对应的命令,但是error bot不起作用
-
从路径中删除
*,并将它们替换为您的真实目录名称。还是您只是“审查”了这个问题的路径?
标签: node.js discord discord.js