【发布时间】:2021-04-27 16:54:17
【问题描述】:
当我想使用不和谐时,我得到了这个错误输出:
Error: ENOENT: no such file or directory, scandir './commands/'
←[90m at Object.readdirSync (fs.js:1021:3)←[39m
at Object.<anonymous> (C:\Users\DAA23\OneDrive\Desktop\bot\main.js:11:25)
←[90m at Module._compile (internal/modules/cjs/loader.js:1063:30)←[39m
←[90m at Object.Module._extensions..js
(internal/modules/cjs/loader.js:1092:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:928:32)←[39m
←[90m at Function.Module._load
(internal/modules/cjs/loader.js:769:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain]
(internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
errno: ←[33m-4058←[39m,
syscall: ←[32m'scandir'←[39m,
code: ←[32m'ENOENT'←[39m,
path: ←[32m'./commands/'←[39m
}
const Discord = require('discord.js')
const client = new Discord.Client();
const prefix = '*';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file =>
file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('ur bot is on');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) ||message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'loop'){
message.channel.send('-loop');
};
});
client.login('xxxxx.xxxxxx');
所以我正在尝试创建一个不和谐机器人,之前它说找不到 discord.js,所以我执行了“npm install discord.js”并删除了不和谐错误,但是它引入了这个错误,我不知道如何修理它。我尝试重新安装 nodejs 并重新安装 discord,但没有任何改变。
【问题讨论】:
-
您好,欢迎来到 SO!从快速超越此错误看来,您的
main.js文件中可能存在错误。你能包括你的项目结构吗?还有一些代码? -
确定我已经在错误下面添加了我的 main.js 代码
-
该错误表示您尝试在
./commands上使用readdirSync,但找不到目录。你能包括你的项目结构/文件夹结构吗? -
文件夹结构是什么意思?你想要 main.js 的目录还是其他的目录?对不起,如果这真的很基础,但我才刚刚开始,我正在努力学习。
-
是的,您的项目的文件夹结构如何?根文件夹?你有什么文件和文件夹?
标签: javascript node.js discord.js