#Adding to DB on the bot startup

21 messages · Page 1 of 1 (latest)

daring coral
#

Hello, So I am looking to make a coin/balance system on my bot using quickDB - I am hoping to find a way to make it so when the bot starts up and when a member joins it adds anyone that is missing to the database.

I have got it setup to make the DB table if it doesnt already exist.

vivid quiver
# daring coral Hello, So I am looking to make a coin/balance system on my bot using quickDB - I...

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

daring coral
#

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

vivid quiver
daring coral
#

Well it seems like I do.

vivid quiver
#

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

daring coral
#

That doesnt make any sense

vivid quiver
#

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

daring coral
#

right, ill just do it my own way - you are making no sense

vivid quiver
#

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???