You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.js v14报错ENOENT:文件存在却提示找不到

文件存在却抛出ENOENT错误(Discord.js v14 + Node.js v18.15.0)

明明目标文件存在,但运行代码时却抛出ENOENT错误:找不到文件或目录,路径为.slashCommands/data/1092748438090829837.json。咨询朋友建议使用优质命令处理器,查阅Discord.js官方文档未找到解决方案,特此求助。

当前使用环境:

  • Discord.js v14
  • Node.js v18.15.0

相关代码片段:

const { MessageEmbed, CommandInteractionOptionResolver, ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js');
const noblox = require('noblox.js');
const fs = require('fs');
const dataDir = '.slashCommands/data/';

module.exports = {
  name: 'update',
  description: 'Update roles for a user',
  type: ApplicationCommandType.ChatInput,
  options: [
    {
      name: 'member',
      type: ApplicationCommandOptionType.User,
      description: 'The member you want to update',
      required: true,
    },
  ],

  run: async (client, interaction) => {
    const userId = interaction.options.getUser('member').id;
    const guildMember = await interaction.guild.members.fetch(userId);
    const guild = interaction.guild;

    // 获取服务器ID
    const guildId = interaction.guild.id;

    // 加载群组数据
    const groups = JSON.parse(fs.readFileSync(`${dataDir}${guildId}.json`, 'utf8'));

文件结构与错误信息截图:

  • 文件结构:文件结构截图
  • 错误信息:错误信息截图

内容的提问来源于stack exchange,提问作者Xeffort

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 16:20:07