Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我';我得到一个文件或目录不';不存在?我把文件夹弄好了吗?_Javascript_Node.js_Visual Studio Code_Directory_Discord.js - Fatal编程技术网

Javascript 为什么我';我得到一个文件或目录不';不存在?我把文件夹弄好了吗?

Javascript 为什么我';我得到一个文件或目录不';不存在?我把文件夹弄好了吗?,javascript,node.js,visual-studio-code,directory,discord.js,Javascript,Node.js,Visual Studio Code,Directory,Discord.js,因此,我编写了以下代码以从以下目录中提取:Commands,如屏幕截图所示: 但我收到一条错误消息,说该文件不存在。该文件与javascript位于同一文件夹中,但javascript似乎无法访问该文件夹。为什么会发生这种情况,我如何修复它 这是代码 const { prefix, token } = require('./config.json'); const fs = require('fs'); const Discord = require('discord.

因此,我编写了以下代码以从以下目录中提取:Commands,如屏幕截图所示:

但我收到一条错误消息,说该文件不存在。该文件与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!');
           }

          });

您的工作场所似乎是“命令”,而您的bot.js却不在那里


您需要将bot.js放在COMMANDS目录中,然后创建另一个名为“COMMANDS”的文件夹,然后在那里放置您的命令。您的工作场所似乎是“COMMANDS”,而您的bot.js不在那里

您需要将bot.js放在COMMANDS目录中,在那里创建另一个名为“COMMANDS”的文件夹,然后在那里放置您的命令