#Quick.db + JS
18 messages · Page 1 of 1 (latest)
Im trying to make castleraid command, which will set on player 24h cooldown in quick.db, also checking if interaction.user has castle, and if another player has castle, everything is fine to this moment, but real thing is when i try to save time in quick.db for one person, and then trying to get it in client.on("ready", () => {
})'
- castleraid command is on another file
I am not sure if you finished completely the sentence but. I am guessing you have a problem with it in the ready event? What is the problem exactly?
yes,
now i see that i lost a few words, my bad
for me, i dont know how to save multiple "time" in quick.db, then calling it in client.on("ready"...
because i cant use interaction.user.id,
There is multiple ways to make this work. This is valid for not only quick.db but mostly any form of data saving by id when you do not have the ids.
The best solution will depend on what you want to do
- You can loop all the user ids. For example, if it is a particular server, you could get the server and gets its members and loop through and check if they have a time in the database and do what is needed if they do.
This in most cases, even if it's only for a server, is not recommended to do. I still give it so you can understand a bit more how you could solve these types of problem but I do not recommend it. It's just bad to do (explained why it is in second method)
- you loop through all the time you set in the database.
This is the best option, since instead of looping through all user ids and checking if a time was saved for them. You loop directly to the saved times in the database which makes less thing to loop through because you will directly only loop on the saved data and now brute force your way into finding which user has a time saved.
In quick.db there is two ways to do this.
A) The more organized way. Quick.db let's you do tables, when doing a table all the data saved will only be in that table and no other data. This makes it easy to get everything after as it is already separate
Ex:
const time = db.table("time");
await time.set("nice", 1);
console.log(await db.get("nice")); // undefined
console.log(await time.get("nice")); // 1
Now to get everything in quick.db, you can use the all method
Here is an example with the time table (note that a quick.db table has all the same method as the basic quick.db instance)
console.log(await time.all());
B) Filtering way. Instead if you don't want to use a table. You can just use db.set normally as well. You will need to be careful with your ids that you use because it will be used to group them together. ( message is too long I have to cut it )
For example, you can use time_ as the start of your ids
await db.set(`time_${userid}`, "your data here");
This will make it possible for you to filter out the data based on the id
const all = await db.all();
const only_time = all.filter(e => e.id.startsWith("time_");
Here I get all the data like for the table one but since it's not a table only for time some other things may be saved as well. Which is why there is the filter to only get those which the id starts with time_
@fierce pulsar I would recommend the second way with either option A or B depending on how you want to do it
You're welcome