GuavaHost
Language & currency
Client AreaGame Panel Toggle navigation
Games All Games
Minecraft JavaMinecraft BedrockMinecraft GeyserRustRuneScape: DragonwildsPalworldValheimValheim + BepInExARK: Survival EvolvedARK: Survival AscendedProject ZomboidEnshroudedDon't Starve TogetherCounter-Strike 2TerrariatModLoaderHytaleMulti-Game ServerDiscord Bot Hosting
Navigation PricingReviewsHelp CenterSupport Company About UsFAQRefer to earnSLATerms of ServicePrivacy Policy
Language & currency
Client AreaGame Panel

Store data for your Discord bot

Anything your bot keeps in memory is gone the moment it restarts, so levels, warnings and per-server settings need to live somewhere on disk. This guide compares a JSON file, SQLite and a MySQL database from the panel, and shows how to back each one up.

6 min read · Updated Oct 21, 2026 · By GuavaHost Team

Why a restart loses everything

A bot is just a program. While it runs, a variable like let warnings = {} lives in memory, and memory belongs to the process. Press Restart, deploy a code change, or let the bot crash, and that process ends and a fresh one starts with empty variables.

That is fine for a dice roller. It is not fine for anything a user would notice losing: XP and levels, moderation warnings, economy balances, a ticket counter, the channel someone configured for logs. Those need to be written to disk as they change, which is what "storage" means here.

There are three sensible options on a GuavaHost bot server, and they go in order of how much work they are.

Option 1: a JSON file

The simplest thing that works. You keep your data in an object, and every time it changes you write the whole object to a file such as data.json next to your bot's code.

In Node.js:

const fs = require('fs');
fs.writeFileSync('./data.json', JSON.stringify(data, null, 2));

In Python:

import json
with open('data.json', 'w') as f:
    json.dump(data, f, indent=2)

On startup you read the file back, and if it does not exist yet you start from an empty object.

Good for: settings, small lists, anything up to a few thousand entries. One server, one bot.

Where it falls over: the whole file is rewritten on every save, so it gets slow as it grows. Worse, if the process is killed halfway through a write, you are left with a truncated file that will not parse, and your data is gone. The usual fix is to write to data.json.tmp and then rename it over the real file, so a half written file never replaces a good one. Do not use a JSON file if two processes might write to it at once: there is no locking, and the last writer wins.

Option 2: SQLite

SQLite is a real database that lives in a single file, with no server to run and nothing to install beyond a library. For a Discord bot it is usually the right answer.

  • Node.js: better-sqlite3 or node:sqlite on recent Node versions.
  • Python: sqlite3 is in the standard library, so there is nothing to add to requirements.txt.

You get proper queries, indexes and transactions, so a crash mid write does not corrupt the file, and reading one user's row does not mean loading every user into memory. A table like CREATE TABLE levels (user_id TEXT PRIMARY KEY, xp INTEGER) will happily hold hundreds of thousands of rows on a bot server.

The file (commonly bot.db or data.sqlite) sits in your server's files like any other file, so it is covered by your backups and you can download it to inspect it locally.

The one catch is better-sqlite3, which is a native module and needs to compile when it installs. If that fails in the Console, installing dependencies for a Discord bot covers what to do about native modules.

Option 3: MySQL from the panel

If your plan includes a database slot, you can create a MySQL database in the panel and point your bot at it. MySQL runs as a separate service, which buys you two things a file cannot:

  • Several processes can read and write safely at the same time. That matters if you run a bot plus a web dashboard, or shard a large bot across more than one process.
  • The data is not inside your server's files, so wiping or reinstalling the server does not take it with it.

Setting up a MySQL database from the panel walks through creating one and where to find the host, port, database name, username and password. Put those values in your bot's environment rather than in your code, the same way you handle your token: see keeping your Discord bot token secret and safe.

Use a connection pool rather than opening a connection per command (mysql2/promise in Node, aiomysql or asyncpg style pools in Python). A bot that opens a new connection on every message will run out of connections under load.

If you do not see Databases in your server menu, your plan has no database slots, and Manage plan is where you can add them.

Picking one

JSON file SQLite Panel MySQL
Setup effort None A library and a table Create it in the panel, add connection details
Safe under a crash No Yes Yes
Handles tens of thousands of rows No Yes Yes
Shared between processes No Not really Yes
Survives a server reinstall No No Yes
Included in file backups Yes Yes No

A fair default: start with a JSON file while you are learning, move to SQLite as soon as you store anything per user, and move to MySQL when more than one process needs the same data.

Where your files live

Both a JSON file and a SQLite database are ordinary files in your server's file area. Open the Files tab to see them, and keep them beside your main file (index.js, bot.py) or in a data/ folder. Using the panel file manager covers browsing and editing files there, and uploading files with SFTP is the comfortable way to pull a database file down to your computer.

One thing to watch: do not open a live SQLite file in a text editor. It is a binary format, and saving it as text will break it.

Backing the data up

Your bot's code is usually safe because it is also on your computer or in a Git repository. The data is not, so it is the part worth protecting.

  1. Open Backups in your server's menu and click Create backup. That captures your files, including a JSON or SQLite data file. Backups: creating, restoring and scheduling shows how to put one on a schedule so you are not relying on remembering.
  2. Keep a copy off the server as well. A backup that lives only on the same machine as the data is one bad day from being no backup at all, and off-site backups explains the add-on that ships your backups elsewhere. How to plan your game server backups covers how often is often enough.
  3. If you use MySQL, back it up separately. Server backups save your files, not your databases. Export it from your own code on a timer, or dump it from your computer using the connection details on the Databases page.

For a SQLite file, the cleanest snapshot is taken while the bot is stopped, because copying a file that is being written to can catch it mid transaction.

Common questions

Will my bot's data survive a restart or a reinstall?

A restart keeps anything you wrote to a file or a database, and loses anything that only existed in memory. A reinstall is different: it replaces your server's files, so a JSON or SQLite file goes with them, while a panel MySQL database stays. Take a backup before any reinstall.

Do I need MySQL for a small bot?

Almost certainly not. SQLite handles far more data than a typical community bot will ever store, needs no credentials and no connection pool, and lives in a single file your backups already cover. Move to MySQL when you have a concrete reason, such as a second process needing the same data.

Can I use MongoDB or Postgres instead?

You can use any database you can reach over the network, including a hosted MongoDB or Postgres service, by putting its connection string in your startup settings. What the panel gives you directly is MySQL, so that is the one with no external account to manage.

Why did my JSON file suddenly fail to parse?

Nearly always because the process stopped partway through a write, leaving the file half finished. Write to a temporary file and rename it over the real one so a save is all or nothing, and keep a backup copy of the last good version.

Still stuck? Jump into our Discord at discord.gg/GuavaHost and the team will help you out.

  • discord bots
  • database
  • mysql
  • sqlite
  • json
  • backups

Host your Discord bot 24/7 From $1.50/mo, with instant setup and DDoS protection.

Still need help? Our team is online 24/7 to answer questions.

Contact support

Related guides

More from Discord Bots.

  • Install dependencies for a Discord bot

    Your bot's libraries are installed for you when the server starts, from package.json on Node.js or requirements.txt on Python. This guide explains where that step happens, how to pin versions, and what to do when an install fails in the console.

    6 min

  • What Is Discord Bot Hosting and How It Works

    Discord bot hosting means running your bot's code on an always-on server so it stays online 24 hours a day, even when your own computer is switched off, and on GuavaHost you run it from your control panel at customer.guavahost.com.

    3 min

  • Discord Bot Keeps Going Offline? 4 Common Fixes

    If your Discord bot keeps dropping offline, it is almost always crashing, running out of memory, hitting a token or intents problem, or simply not being hosted on an always-on server, and this guide walks through each cause and its fix.

    3 min

  • Read your Discord bot's logs and find the error

    When a bot crashes, stops responding or never comes online, the answer is almost always in its log. This guide shows you how to read the console, make sense of a stack trace or traceback, add logging of your own, and recognise the intent, permission and rate limit errors Discord sends back.

    7 min

  • How to Host a Node.js (discord.js) Bot

    This guide walks you through uploading a Node.js bot built with discord.js to your GuavaHost control panel, installing its dependencies from package.json, and starting it with the right command so it runs 24/7.

    3 min