#Adding to DB on the bot startup
21 messages · Page 1 of 1 (latest)
Most of the things you are talking about is done by quick.db which you don't have to worry about doing.
For example the db table.
That is already done by quick.db which will make sure to create it if it doesn't exist, even if you use a custom table with db.table.
You also don't need to initialize data for all members as well. For example when using db.add to add coin to user quick.db will check if it exists. If it doesn't quick.db will use 0 and add the value if not it will add to the current value in the db.
If you still want to initialize all members on join and on the bot going online than it is mostly a discord.js question.
You would need to use the events discord.js gives you. For example in the past it was called guildMemberAdd or something close. Not sure if it still called this
right
so for all the command I need to add an if statement, to add them into the DB if they dont already...
Because When I do /give it doesnt give them any coins because they dont exist in the db
Like I just said, you don't have to do that
Well it seems like I do.
If you add the values yourself yes
Not if you use db.add
Db.add like I said, will use 0 if the entry is not found
So if the command adds 5
It will do 0 + 5
If the entry as a value it will use that value + 5
That doesnt make any sense
If you don't use db.add than yeah, that won't be done since you will have to handle it. That is why we give this function so it's easier
right, ill just do it my own way - you are making no sense
What doesn't make sense exactly?
Here is a simple snippet
await db.set("nick", 10);
await db.add("nick", 20);
await db.add("doesntexist", 20);
Nick will be at 30 since it already had 10 before adding
But since doesntexist had nothing. It will be at 20 because quick.db nows it didn't have any value
oh he left???