Storing data your bot needs to remember

Discord Bots Reviewed September 6, 2026 2 min read

The moment your bot has to remember something between restarts, you need somewhere to put it. There are three reasonable answers and the wrong one only becomes obvious later, when the data is already there.

Choosing

OptionGood forFalls over when
A JSON fileSettings, small lists, a few dozen entriesTwo writes overlap, or the process dies mid-write
SQLiteMost bots. Thousands of rows, real queries, one fileSeveral processes write at once
MySQLSharded bots, dashboards, data shared with a websiteNothing, but it is more to set up
A JSON file will lose data eventually

Writing the whole file on every change means a crash during a write leaves it truncated or empty. It is fine for config you edit by hand; it is a bad home for anything users generate. If you must, write to a temporary file and rename it over the original — a rename is atomic and cannot half-happen.

Moving from JSON to SQLite

  1. Add the library

    better-sqlite3 in Node, or the built-in sqlite3 module in Python. No server to run — the database is one file next to your code.

  2. Create the table to match what you already store

    One column per key you were writing. Keep the same names so the migration script is obvious.

  3. Write a one-off import

    Read the JSON, insert the rows, keep the old file until you are sure. Deleting it a week later costs nothing; deleting it early costs everything.

  4. Include the database file in your backups

    It is now the only copy of everything your bot knows.

Whatever you choose, back it up on a schedule

The database file is the part of your bot you cannot rewrite from memory. Code you can push again from your laptop; a year of user settings you cannot.