#How to make a warn with a database
24 messages · Page 1 of 1 (latest)
Well, have a user schema for warn data for user, so inside the schema you'll have like an array named warns or however you'd like to customize it,
have a command to warn a user,
inside the command check if the user has data, if not create the data for the warns. If the user has data, push to the warns. After you've pushed to the warns and saved the data, check if the user has 3 warns and then if they do, kick the user. If u want u can clear the warns or whatever you'd like, jus a basic understanding of how I'd do it
what's a schema?
I recommend mongodb database, use the mongoose package, it's a mongodb wrapper
It's something you add to a model and a model is basically data in mongodb, watch a mongoose mongodb course or tutorial on youtube and when you get a basic understanding, you can attempt and then come here if you need help
ok thank you, does discordJS docs have a tutorial kind of thing by any chance?
As for the spamming, when the user sends a message, store the ID of the user in a collection or have like a boolean in the database and when the user sends a message, check if the boolean is truthy or if the user is in the collection. If they are, warn them. After some time, (the cooldown), remove the ID of the user or set the boolean to a falsey value
Not to my knowledge, you're gonna have to use your imagination for this one.
You can use prior knowledge in databases , collections, or javascript to make this
i don't have any knowledge with databases as i've never used one
thank you @swift narwhal 🙂
there are tutorials on youtube so i think that they will help
Damn, well it's gonna be important for this
You should also check the sites for the database or package that you're going to use, tutorials are another person's understanding of how to use the database or package so you shouldn't go entirely off what they say and have your own understanding as well
ok thank you 🙏
There are many databases out there, i'd say the simplest isnt even a database but a json file. Let's go over the basic concepts of this:
When you warn the user, store the userID in a json file. for example:
{
"234091823091283": {
"warns": 1
}
}
increase the warns value each time (you can ofcourse add extra data after the warns value like the amount of kicks or bans or whatever)
Then when you warn the user check the warns and if they reach a certain number ban/kick/do whatever with the user (you get the user by the userID)
I hope you understood my explanation.
thank you very much, that helps so much more as i don't have any knowledge with databases, one question, do i have to add these warns manually?
You would write logic, for example a slash command, to communicate with your database. An example for mongo, to create a new document in a collection using your schema
warnings.create({
userId: 'xxxxxxxxxx',
reason: 'Being an idiot'
});
I would recommend taking a look at the mongo docs https://www.mongodb.com/docs/
i think i am going to stick with the json one, sorry
No sweat 
Well no. Every time someone runs the warn command it just adds to the warns thing
without a database?
Yes without a database. Pseudo code:
json[USERID][warns] += 1
i might just follow a tutorial on yt