gpt4 book ai didi

javascript - 为什么 fs.readFileSync 会出现未知错误

转载 作者:行者123 更新时间:2023-11-29 22:48:07 25 4
gpt4 key购买 nike

我是初学者,我正在尝试创建一个 discord 机器人警告系统,有一个文件存储用户 ID 和警告计数。我使用的 Node 版本是 10.16.3,我以前使用的是 12.10.0 我尝试了两个 Node 版本但没有用。这是命令和错误:

 const Disord = require ("discord.js")
const fs = require ("fs")
const ms = require ("ms")
let warns = JSON.parse(fs.readlinkSync("./uyarilar.json", "utf8"));

module.exports.run = async (bot, message, args) => {

if (!message.member.hasPermission("MANAGE_MEMBERS")) return message.reply("Uyarmak istediğin kişi yetkili.");
let wUser = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
if(!wUser) return message.reply("Uyarmak istediğin kişiyi bulamadım.");
if(wUser.hasPermission("MANAGE_MESSAGES")) return message.reply("Uyarmak istediğin kişi yetkili.");
let reason = args.join(" ").slice(22);

if(!warns[wUser.id]) warns[wUser.id] = id
warns: 0

warns[wUser.id].warns++;

fs.writeFile("./uyarilar.json", JSON.stringify(warns), (err) => {
if (err) console.log(err);
});

let warnEmbed = new DiscordRichEmbed()
.setDescription("Uyarı")
.setAuthor(message.author.wUsername)
.setColor(RANDOM)
.addField("Uyarılan kişi", wUser.tag)
.addField("Uyarıldığı kanal", message.channel)
.addField("Toplam uyarılar", warns[wUser.id]
.addField("Sebep", reason));

let warnchannel = message.guilds.channels.find("name", "uyarılar");
if(!warnchannel) return message.reply("Uyarılar kanalını bulamadım.");

warnchannel.send(warnEmbed);

if(warns[wUser.id].warns == 2){
let muterole = message.guild.roles.find("name", "TimeMuted");
if(!muterole) return message.reply("TimeMuted Rolünü bulamadım.");

let mutetime = "10h";
await(wUser.addRole(muterole.id));
message.channel.send("{$wUser.tag} 10 saatliğine susturuldu")

setTimeout(function(){
wUser.removeRole(muterole.id)
message.channel.reply("{$wUser.tag} adlı kişinin susturulması bitti!")
}, ms(mutetime))
}
if(warns[wUser.id].warns == 4){
message.guild.member(wUser).kick(reason);
message.send.channel("$wUser.tag} adlı kişi sunucudan atıldı.")
}


}

module.exports.conf = {
enabled: true,
guildOnly: true,
aliases: ["warn", "uyarı-ver"],
permLevel: 2,
kategori: "moderasyon"
}

module.exports.help = {
name: 'uyar',
category: 'moderasyon',
description: 'İstediğiniz kişiyi uyarır.',
usage: 'uyar [@kullanıcı] [<sebep>]'
}

错误:

fs.js:114
throw err;
^

Error: UNKNOWN: unknown error, readlink './uyarilar.json'
at Object.readlinkSync (fs.js:876:3)
at Object.<anonymous> (C:\Users\dbk20\OneDrive\Masaüstü\GZBOT\komutlar\uyari.js:4:27)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at files.forEach.f (C:\Users\dbk20\OneDrive\Masaüstü\GZBOT\bot.js:64:17)

感谢您的帮助。

最佳答案

在您的代码中调用 readlinkSync,而不是 readFileSync

readlinkSync 正在调用 readlink :

readlink, readlinkat - read value of a symbolic link

我很确定您想改为调用 readFileSync。

关于javascript - 为什么 fs.readFileSync 会出现未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57962641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com