How do i save data on my discord bot

so i am trying to make a warning system but i need to store data but i dont know how i would save data because i know glitch doesnt let you write data to editor

For my Discord bots I always use Firebase as a database.

Take a look at something like SQLite, endb, or JSONing.

Hey @TheDooM,

You can use a database to store data. In your Glitch project, the most reasonable database to use would be an SQLite database. And to make things easier, you can use a database adapter like Endb.

  1. Make sure you’ve installed Endb, using npm i endb.
  2. For an SQLite database, you’ll have to download 2 more packages additionally:
npm i sql
npm i sqlite3
  1. Then at the top of your code, add
const Endb = require('endb');
  1. Then you can create an SQLite database:
const endb = new Endb('sqlite://DATABASE_FILE_NAME.sqlite');

Make sure to replace DATABASE_FILE_NAME with the name you want to give to your database.

  1. Then anywhere in your code, you can use methods such as
  • endb.set("KEY", "VALUE") (for setting a new element to the database with a key and a value)
  • endb.get("KEY") (for getting the value of an element based on the key)
  • endb.delete("KEY") (delete an element based on the key)
  • endb.all() (get all the elements of your database)

VALUE can be of almost any data type, including objects and arrays.

See https://endb.js.org to read Endb’s whole documentation.

2 Likes

Hi!

You could use a simple JSON file which you write your data (Object or Array) into using:

const fs = require('fs');
fs.writeFileSync(PATH, JSON.stringify(OUTPUT));

Enmap is also a great better-sqlite3 adapter, but there only are a few tutorials on youtube about it. It’s mostly based on Discord.js collections, so if you’ve worked with those before, enmap can be very handy.

I’ve also used MongoDB, you can interact with your database using the mongoose module.

I’ve used enmap a lot because of its simplicity, it’s also super fast and I used Discord.js collections everywhere in my bot, it’s basically the same synthax.

JSON is prone to corruption, there are JSON-based data store packages like Jsoning

1 Like

Other database adapters include Quick.db.

3 Likes

i already knew about json but i have a understanding how glitch shows stuff in editor and stuff and i know that wont work perfect

npm WARN discord.js@11.5.1 requires a peer of @discordjs/uws@^10.149.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.5.1 requires a peer of bufferutil@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.5.1 requires a peer of erlpack@discordapp/erlpack but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.5.1 requires a peer of libsodium-wrappers@^0.7.3 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.5.1 requires a peer of node-opus@^0.2.7 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.5.1 requires a peer of opusscript@^0.0.6 but none is installed. You must install peer dependencies yourself.
npm WARN discord.js@11.5.1 requires a peer of sodium@^2.0.3 but none is installed. You must install peer dependencies yourself.

it says when i install endb

It’s okay, just a warning, you can ignore it.

Error: Cannot find module ‘endb’

Did you install Endb using npm install endb?

yep and even refreshsed

Try npm rebuild in the console.

1 Like

how do i make a coloum because i want to store discord user ids as colum names

Did you add endb in package.json?

1 Like

yes this is my package.json {
“//1”: “describes your app and its dependencies”,
“//2”: “https://docs.npmjs.com/files/package.json”,
“//3”: “updating this file will download and update your packages”,
“name”: “hello-express”,
“version”: “0.0.1”,
“description”: “A simple Node app built on Express, instantly up and running.”,
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
},
“dependencies”: {
“discord.js”: “^11.5.1”,
“endb”: “^0.23.0”,
“express”: “^4.16.4”,
“express.js”: “^1.0.0”,
“profanities”: “^2.13.0”,
“sql”: “^0.78.0”,
“sqlite3”: “^4.2.0”
},
“engines”: {
“node”: “8.x”
},
“repository”: {
“url”: “https://glitch.com/edit/#!/hello-express
},
“license”: “MIT”,
“keywords”: [
“node”,
“glitch”,
“express”
]
}

i get Cannot Find Module @endb/sqlite
I installed it
I even tried npm rebuild but nothing

The package exists, are you sure you installed it correctly?