【问题标题】:Error: ENOENT: no such file or directory, mkdir错误:ENOENT:没有这样的文件或目录,mkdir
【发布时间】:2022-01-16 11:05:39
【问题描述】:

我今天将我的代码更新到 v13,现在当我尝试启动我的不和谐机器人时,我遇到了一个错误,但是当我回到 v12 时,这个错误不再在这里了.. https://pastebin.com/9puJMkSQ 这是我的代码

 constructor(guild) {
        this.guild = guild;

        const storagePath = "./root/DiscordMusicGiveawayBotNew/storage/"
        if (!fs.existsSync(storagePath)) {
            fs.mkdirSync(storagePath);
        }

        const myStorage = "./root/DiscordMusicGiveawayBotNew/storage/" + this.guild.name;
        if (!fs.existsSync(myStorage)) {
            fs.mkdirSync(myStorage);
        }

        const dirPath = './root/DiscordMusicGiveawayBotNew/storage/' + this.guild.name + "/giveaways";

        if (!fs.existsSync(dirPath)) {
            fs.mkdirSync(dirPath);
        }

        const dir = fs.opendirSync(dirPath);

它有什么问题?它在 v12 中完美运行,但是当我更改为 v13 时,它返回一个错误,阻止我们启动我们的代码

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    我相信您需要传递recursive: true 选项。我认为这与 NodeJS 版本无关。

    fs.mkdirSync(storagePath, { recursive: true })

    【讨论】:

    • 我试过了,但它给了我另一个错误:/root/DiscordMusicGiveawayBotNew/guildStorage.js:68 fs.mkdirSync(myStorage,{recursive:true}); ^ ReferenceError:在初始化之前无法访问“myStorage”
    • 这是 JS 语法错误。在初始化变量之前不要使用变量
    猜你喜欢
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 2019-03-09
    • 2017-12-28
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多