【问题标题】:How come I'm getting a This File or Directory doesn't exist? I have made the folder?为什么我得到这个文件或目录不存在?我做了文件夹?
【发布时间】:2021-02-23 17:15:17
【问题描述】:

所以我制作了这段代码来从这个目录中提取:命令,正如你在屏幕截图中看到的那样:

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

          });

【问题讨论】:

    标签: javascript node.js visual-studio-code directory discord.js


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 2021-01-07
      • 1970-01-01
      • 2012-01-04
      • 2011-12-14
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多