ViridianZe
ViridianZe

Reputation: 121

Discord.js Counter and storing

I know this may seem easy but I haven't delved too deeply into Javascript or any code for that matter but I'm doing so now that I am making a discord bot I can't seem to find a way to make a counter for my discord bot so if someone says "!pointsadd 100" then it would add 100 to the balance and that can be taken away from ect. can find other counters like HTML, CSS but the format is confusing to me if anyone could help much appreciated

Upvotes: 2

Views: 997

Answers (2)

ShadowChan
ShadowChan

Reputation: 36

If you would like a reliable way to store the points value, try using something like MongoDB. I could help with it if you want. Although if you just want to store it in a plain old JSON file (wouldn't recommend, they can corrupt after being written to too often) https://www.youtube.com/watch?v=Aw4b2VN1KW8 this is a good video to follow.

Upvotes: 2

Viriato
Viriato

Reputation: 141

Try using the message event listener to trigger a specific function when someone uses the command "!pointsadd":

client.on('message', function (message) {
    let args = message.content.split(' ');

    switch(args[0].toLowerCase()) {
        case '!pointsadd':
            addPoints();
            break;
         default:
            break;
    }
}

Then you can try to create a JSON file with an object with property 'balance':

{
    "balance": 0
}

Parse it into your javascript file and modify it using File System

Upvotes: 1

Related Questions