简体   繁体   中英

How to locate a file discord.js v12?

I've run into a problem that I can't locate an existing file. My code looks like this:

const { DiscordAPIError } = require("discord.js");
const Discord = require("discord.js");
const fs = require("fs");
//const ms = require("ms");
let pats = JSON.parse(fs.readFileSync("../values/pats.json", "utf-8"));

module.exports = {
  name: "pat",
  description: "The bot will pat the mentioned user",
  execute(message, args) {
    let pats = JSON.parse(fs.readFileSync("../values/pat.json", "utf-8"));
    var pattedone = message.guild.member(message.mentions.members.first());
    if (!pats[pattedone.id])
      pats[pattedone.id] = {
        pats: 0,
      };
  },
};

but I get an error no such file or directory, open '../values/pat.json' Any help?

Have you tried changing this:

let pats = JSON.parse(fs.readFileSync("../values/pats.json", "utf-8"));

to this:?

let pats = JSON.parse(fs.readFileSync("./values/pats.json", "utf-8"));

I made the same mistake a while ago and that helped me. (remove one dot)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM