JSON File Counter

I am trying to make a simple word counter in discord.js I have managed to get the bot counting the specific word i want to be counted but how do i permanently store this data in a JSON file and update it when the bot is active.
26 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna16mo ago
the thing you are looking for is probably a database, and not really djs related
Nixx
NixxOP16mo ago
but i am using it for a bot through discord.js
gracey
gracey16mo ago
don’t store data in a json file, it’s not a file storage solution
Nixx
NixxOP16mo ago
its for a small scale thing just messing around
gracey
gracey16mo ago
It’s slow, prone to failure and slower to write and read than most databases SQLITE etc are very easy to setup and learn much quicker and more efficient that json
Nixx
NixxOP16mo ago
Okay I will look into it now and see
gracey
gracey16mo ago
You can handle processes within an sql db too, for example with a JSON file you have to fetch and filter the whole data, whereas with sql you can grab any data from any any column or row in w few words SELECT * FROM table WHERE condition will get you a row of data dtored
treble/luna
treble/luna16mo ago
depeneds if you want to use SQL or NoSQL though
Nixx
NixxOP16mo ago
see i wanted it so when the bot saw the word "example" it would reply saying "this user has said 'example' 4 times" or something I want to use something lite and easy to setup nothing to complex
treble/luna
treble/luna16mo ago
i find mongodb very easy to work with
gracey
gracey16mo ago
For something like this use a table then, NoSQL might be difficult to understand and keep organised You don’t need to store that though, discord has history as an attribute if you’re only doing stuff locally. Plus, why make this if discord search enables this anyway?
treble/luna
treble/luna16mo ago
uhh bots cannot access search
gracey
gracey16mo ago
no but people can
treble/luna
treble/luna16mo ago
yes but this is about using a bot
gracey
gracey16mo ago
Im aware Im just saying that if this is a feature already enabled in discord, there isn’t a large point in making a feature like that
treble/luna
treble/luna16mo ago
depends on use case regardless for db
gracey
gracey16mo ago
each to their own though
d.js docs
d.js docs16mo ago
guide Databases: Initialize database read more
Nixx
NixxOP16mo ago
client.on('messageCreate', (message) => {
if (message.content == 'word') {
countWord++ == countWord;
message.reply(`I have detected the word 'hello' by ${message.author.tag} this user has said this ${countWord} times.`);
}
});
client.on('messageCreate', (message) => {
if (message.content == 'word') {
countWord++ == countWord;
message.reply(`I have detected the word 'hello' by ${message.author.tag} this user has said this ${countWord} times.`);
}
});
this is what is being done now and essentially when i restart the bot it looses its count all i want to do is permantly store the count
treble/luna
treble/luna16mo ago
use a db then
Nixx
NixxOP16mo ago
is there an easier way without setting up a whole db though? I have never used dbs thats why im trying to avoid it 😭
treble/luna
treble/luna16mo ago
you can store it in a file but thats slow and if something happens when your bot writes to the file funky stuff might happen with that file
Nixx
NixxOP16mo ago
I understand So mongodb and sqlite are the recommendations?
treble/luna
treble/luna16mo ago
i personally use mongodb since dont want to use SQL
Nixx
NixxOP16mo ago
Okay thank you, I will mark this question as solved. Thank you!
Want results from more Discord servers?
Add your server