亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我收到此文件或目錄不存在?我已經制作了文件夾嗎?

為什么我收到此文件或目錄不存在?我已經制作了文件夾嗎?

波斯汪 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 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號