因此,我編寫了從該目錄:命令中提取的代碼,我收到一條錯誤消息,指出該文件不存在。該文件與 javascript 位于同一文件夾中,但 javascript 似乎無法訪問該文件夾。為什么會發生這種情況以及如何解決它。這是代碼? const { prefix, token } = require('./config.json');? ? const fs = require('fs');? ? const Discord = require('discord.js');? ? const client = new Discord.Client();? ? 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('Ready!');? ? ?});? ? ? client.login(token);? ? ? ? ?client.on ('message', message => {? ? ? ? ?if (!message.content.startsWith(prefix) || message.author.bot) return;? ? ? ? ? const args = message.content.slice(prefix.length).trim().split(/ +/);? ? ? ? ? ? ? ? const command = args.shift().toLowerCase();? ? ? ? ? ? ? ?if (!client.commands.has(command)) return;? ? try {? ? ? client.commands.get(command).execute(message, args);? ? ? ?} catch (error) {? ? ? ? ? console.error(error);? ? ? ? ? message.reply('there was an error trying to execute that command!');? ? ? ? ? ?}? ? ? ? ? });
為什么我收到此文件或目錄不存在?我已經制作了文件夾嗎?
波斯汪
2023-07-29 14:50:10