为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我收到此文件或目录不存在?我已经制作了文件夹吗?

为什么我收到此文件或目录不存在?我已经制作了文件夹吗?

波斯汪 2023-07-29 14:50:10
因此,我编写了从该目录:命令中提取的代码,我收到一条错误消息,指出该文件不存在。该文件与 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!');           }          });
查看完整描述

1 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

看来您的工作场所是“命令”,而您的 bot.js 不在那里。

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


查看完整回答
反对 回复 2023-07-29
  • 1 回答
  • 0 关注
  • 61 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信