Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

discord - How to reset loaded data from JSON file

I have leveling system and I have made a command for it what shows how much xp and what level you are, but there is the problem when you execute the command it gives you the same level and xp from the moment that the bot is online. I mean that even you gain xp and have leveled up it doesn't update it in the command because in the JSON file is instantly updated.

For example I start the bot and when I start it I have 24 xp and I'm level 2 but I chat and gain more xp and level without restarting the bot. It saves it in the JSON file, but when you execute the command it shows you your level from the beginning (24 xp and level 2)

I want somehow to reread the file everytime the command is excuted or if you have better idea I won't say no to it.

For executing the commands I use command handler. And in the command code I have build canvacord card and simple const that doesn't enclude any of the JSON data (both are not shown because don't give information about the problem).

Here is my command:

const fs = require('fs');
const Discord = require('discord.js');
const canvacord = require("canvacord");

const stats = JSON.parse(fs.readFileSync('stats.json'));

module.exports = {
    name: 'level',
    description: 'Shows members what level they are.',
    cooldown: 5,
    guildOnly: true,
    execute(bot, message, args) {
        const user = message.author;
        guild = stats[message.guild.id];
        userData = guild[message.author.id];

        //the code that is not shown doesn't include json data and if it includes is from the only shown part of the code.
        //simple formula..

        //the canvacord build...

        });
    },
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...