How to you store data for each discord user in the discord server?

Required Dependencies: sqlite

Well considering that this question is very general, I’ll give a fairly general answer. Knowing that you’re using discord.js

One way you can complete your goal, is by creating an sqlite database. Note: this does not involve variables. To do this, you will have to require sqlite as a dependency:

const sql = require("sqlite");

Once completed this, you can create the file, the database will be in:"./database.sqlite")

After which you will set up the table for the users:"CREATE TABLE IF NOT EXISTS userData (userId TEXT, money INTEGER)").then(() => {"INSERT INTO userData (userId, money) VALUES (?, ?)", [<user id object here>, 0]);

That would create a database you can use to store information about each user in your guild.

After which to update their balance follow this format (example):

sql.get(`SELECT * FROM userData WHERE userId = ${}`).then(row => { //the row is the user's data
    if(!row) { //if the user is not in the database"INSERT INTO userData (userId, money) VALUES (?, ?)", [`${guildId}`, <user id object here>, 0]); //let's just insert them"Registered.")
    } else { //if the user is in the database`UPDATE userData SET money = ${ + 100} WHERE guild = ${}`)

If there are issues in the code provided or errors, feel free to comment or contact me 🙂

Leave a Comment