I have a question. How can I let my DiscordBot write and read a JSON file? I have already programmed something but have only error. Can someone help me out? I would appreciate any help.
const Discord = require("discord.js")
const botconfig = require("../botconfig.json");
const colours = require("../colours.json");
const superagent = require("superagent");
const { report } = require("superagent");
const usedCommand = new Set();
module.exports.run = async(bot, message, args) => {
message.delete();
if (usedCommand.has(message.author.id)) {
message.reply("du kannst diesen Command erst in 15 Sekunden wieder verwenden.").then(msg => msg.delete({ timeout: "10000" }));
} else {
let member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
let reason = args.slice(1).join(" ");
if (!reason) message.reply("Bitte gebe einen Beweis in Form von einem Link (Video: Youtube, Bild: prnt.sc) an!")
var fs = require("fs");
var sampleObject = {
username: member,
proof: reason
};
fs.writeFile('../rpp.json', JSON.stringify(sampleObject, null, 4), (err) => {
if (err) {
console.error(err);
return;
};
console.log("File has been created");
});
usedCommand.add(message.author.id);
setTimeout(() => {
usedCommand.delete(message.author.id);
}, 15000);
}
}
module.exports.config = {
name: "rpp",
description: "Bans a user from the guild!",
usage: "+ban",
accessableby: "Members",
aliases: ["proofwrite"]
}
I want my Discord bot to enter the tagged user and a reason into the JSON file using the "writerrp" command. After that I want the bot to read the data of a user with the "readrrp" command.