为什么我的不和谐机器人两次请求同一个文件夹?

问题描述 投票:0回答:1

尝试为个人工具(例如禁止、踢)制作一个私人不和谐机器人。用户信息...但是当我尝试启动机器人时,我收到此错误:

C:\Program Files\nodejs\node.exe .\index.js
Uncaught Error Error: ENOENT: no such file or directory, scandir 'D:\Rubytoolbot\Rubytoolbot\commands'
    at readdirSync (fs:1508:26)
    at <anonymous> (d:\Rubytoolbot\index.js:19:25)
    at Module._compile (internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (internal/modules/cjs/loader:1426:10)
    at Module.load (internal/modules/cjs/loader:1205:32)
    at Module._load (internal/modules/cjs/loader:1021:12)
    at executeUserEntryPoint (internal/modules/run_main:142:12)
    at <anonymous> (internal/main/run_main_module:28:49)
Process exited with code 1

第 14 行到 25 行的一段代码

    GatewayIntentBits.GuildVoiceStates,
  ],
});
client.commands = new Collection(); // Saving the commands

const commandFiles = fs.readdirSync('./Rubytoolbot/commands').filter(file => file.endsWith('.js'));

commandFiles.forEach((commandFile) => {
  const command = require(`./Rubytoolbot/commands/${commandFile}`);

  client.commands.set(command.data.name, command);
});

尝试将 ./Rubytoolbot/commands 更改为 D:/Rubytoolbot/commands 但得到相同的结果。我希望它能毫无问题地工作

node.js discord discord.js bots
1个回答
0
投票

您提供的代码是否在

Rubytoolbot
目录中运行?如果是这样,您只需将
./Rubytoolbot/commands
更改为
./commands

文件路径的

./
部分表示当前目录,通过编写
./Rubytoolbot/commands
,您实际上是在查找
./Rubytoolbot/Rubytoolbot/commands
目录,该目录不存在。

© www.soinside.com 2019 - 2024. All rights reserved.