I am trying to log a arg to json but its giving me 0 error means it not getting input or undefined but in console.log it displays the args clearly what can i do ?
const fs = require('fs')
module.exports = {
name: "write",
category: "fun",
description: "Save 1 message in our database",
run: async (client, message, args) => {
let save = args.join(" ");
console.log(save)
let msgs = JSON.parse(fs.readFileSync("./message.json", "utf8"));
msgs[message.guild.id] = {
msgs: save
};
await fs.writeFile("./message.json", JSON.stringify(msgs), (err) => {
if (err) throw err;
message.channel.send("message logged");
});
}
}
It seems the message.json isn't a valid JSON. Instead, wrap the code in a try-catch so that error can be handled here. Also, try to log the msgs so that output can be viewed.
try {
let msgs = JSON.parse(fs.readFileSync("./message.json", "utf8"));
msgs[message.guild.id] = {
msgs: save
};
await fs.writeFile("./message.json", JSON.stringify(msgs), (err) => {
if (err) throw err;
message.channel.send("message logged");
});
} catch(e) {
console.log(e.message);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments