Database¶
NadekoBot keeps all server settings and member data in one SQLite file, NadekoBot.db. This page is for the owner of a self-hosted bot.
You do not have to make the file. The bot creates it on the first start.
Find the database¶
The database is in the bot's data folder:
| Install | Database file |
|---|---|
| Desktop guide (Upeko) | data/NadekoBot.db in the folder of Install Path on the bot page. Click Data Folder in Shortcuts to open it. On Windows, the default folder is Documents\upeko\bot-xxxxx. |
| CLI guide | nadeko/data/NadekoBot.db in your home folder |
| Docker guide | data/NadekoBot.db in the bot's folder, for example ~/nadeko/data/NadekoBot.db |
| Source guide | nadekobot/src/NadekoBot/data/NadekoBot.db |
The bot reads data in the folder where it starts. If you start the built program from bin/Release/net9.0 (for example from an IDE), the database is in bin/Release/net9.0/data. A build copies the files of src/NadekoBot/data into that folder and can replace the database there. Always start the bot from the same folder, and edit the database in that folder.
While the bot runs, you can also see the files NadekoBot.db-wal and NadekoBot.db-shm. They are part of the database. Keep them together with NadekoBot.db.
Get a database tool¶
Install DB Browser for SQLite.
Install the sqlite3 program:
sudo apt install sqlite3
On Fedora, use sudo dnf install sqlite. You can also use DB Browser for SQLite if your computer has a desktop.
Edit the database¶
Stop the bot and make a backup first
If you change the file while the bot runs, you can lose the change or damage the file. A wrong change can break the bot. Always stop the bot and copy the files before you edit them.
- Stop the bot. Type
.diein Discord, or click Stop Instance in Upeko. With systemd, typesudo systemctl stop nadeko. With Docker, typedocker stop nadeko. - Copy
NadekoBot.dbto a safe place. IfNadekoBot.db-walandNadekoBot.db-shmare in the folder, copy them too. -
Edit the database:
- Click Open Database and select
NadekoBot.db. - Open the Browse Data tab.
- In the Table list, select the table.
- Click the cell which you want to change.
- Type the new value in the Edit Database Cell pane on the right.
- Click Apply.
- Click Write Changes.
- Close DB Browser for SQLite.
-
Open the database. For example, with the CLI install:
sqlite3 ~/nadeko/data/NadekoBot.dbWith Docker, the bot writes its files as
root. Usesudo sqlite3 ~/nadeko/data/NadekoBot.db. -
Type
.tablesto show the tables, and.schema DiscordUserto show the columns of a table. -
Type your SQL. End each statement with
;. For example, to give a member 1000 currency:UPDATE DiscordUser SET CurrencyAmount = CurrencyAmount + 1000 WHERE UserId = 123456789012345678; -
Type
.quit.
- Click Open Database and select
-
Start the bot.
If the bot does not start after your change, restore the backup: stop the bot, move NadekoBot.db, NadekoBot.db-wal and NadekoBot.db-shm to a different folder, then copy your backup files back.
Use SQL from Discord¶
The owner can also read and change the database in Discord, while the bot runs:
.sqlselect <sql>shows the result of a query which only reads. It works only in DMs with the bot..sqlselectcsv <sql>sends the result as a CSV file. It works only in DMs with the bot..sqlexec <sql>runs SQL which changes the database. The bot asks you to confirm first.
For example: .sqlselect SELECT UserId, CurrencyAmount FROM DiscordUser ORDER BY CurrencyAmount DESC LIMIT 10
Many changes have a command, for example .award for currency. Use the command when there is one.