Skip to main content
chapterjs dev runs the bot of the current folder on your test server, and reloads your files when you save them. It is what the dev script of your project starts:
That is all: the bot is online in your test server, your commands show up there, and every file of src/ is watched. Everything the command needs from Discord is worked out from your files: the intents of the second line, what the bot remembers, the commands to register.
The options, the environment variables and the exit codes of the command are in the CLI reference.

What it needs

A .env file at the root of your project, with two values:
.env
Where to find them is in Your Discord application. A value set in the real environment wins over the file.
BOT_TOKEN is the token of a dev application, not of the bot that goes online for everyone. We recommend two applications from the start: one bot for your computer, one bot for production. With one bot for both, your test server shows every command you are changing twice, and the presence, the privileged intents and the token of production are shared with what you try. How to set it up: A second bot for development.
Without the file, the command stops before anything else:
And it must run in the folder of your bot, the one with package.json and src/:

What it checks for you

Before connecting, chapterjs dev makes sure everything is in place. When something is missing, it says what and how to fix it, and when you are in a terminal it waits for the fix instead of making you start again:
Every problem is printed at once: a value that is empty, still the example value, a token with a space in it, a server ID that is not made of digits. The command stops; fix .env and start it again.
Discord does not recognize the token, usually because it was reset. The command stops.
You get a link that adds the bot to that server, with every permission: a test server is a playground. Open it, confirm, and the command goes on by itself.
Some events need an option enabled for your bot in the Developer Portal. You get the files that need it and the link to the right page. Enable it, save, and the command goes on by itself.
The three options and which files need them are in Your Discord application.
The command only waits when it runs in a terminal. Started by another program, the same two messages are errors (✗) and the command stops with exit code 1.

Reload on save

Save a file and your bot uses the new version, without disconnecting:
Every file under src/ is watched: your commands, your events and the files they import. A new file or a new folder is picked up as soon as it is saved, and several files saved at once are one reload. A file saved while the command was starting is not lost: it is reloaded right after. A file with a mistake never stops your bot. The error is shown with the file and the line, and the last version that worked keeps running until you fix it:
With several broken files, the message counts them: ⚠ Reloaded with 2 errors: those files keep running their last working version. A file that never worked is left out until it does.
Reloading starts your files again from scratch: a variable kept in a file (a counter, a list…) goes back to its first value on every save. Packages from node_modules are not reloaded.

When your files need more from Discord

The intents are given to Discord when the bot connects. When a file you save needs one the connection does not have (a new event, a file that now listens to private messages), the bot reconnects by itself:
If that intent is privileged and not enabled yet, you get the same message and the same wait as before connecting. The ready event runs once per start, not when the bot reconnects.

Your commands on your test server

Your commands are registered on your test server only, where they show up at once. Discord is told again only when something people see changed (a name, a description, an option, a translation): changing what a command does costs no request, and neither does starting the bot again.
On a reload, the line is ↻ Commands updated on My Server. When Discord refuses what your files declare, the bot keeps running with the commands Discord already has:
A command that production already shows for everyone, exactly as your file declares it, is not added a second time. While you are changing one, your test server shows it twice and the command tells you once:
A dev application never shows that: see A second bot for development.

Only your test server

In dev, your bot only sees the server of DEV_GUILD_ID. What happens in the other servers it is in, and in private messages, is ignored, and the intents that only serve private messages are not asked for. That is for chapterjs start, which can run the same bot for everyone at the same time. What only works in private messages can’t be tried in dev, and chapterjs dev names the file once:

The types of your project

When it starts, chapterjs dev writes the types of your project in the .chapterjs/ folder: what your project adds to the types of chapterjs, the files of public/ that asset() offers, your languages, which type t, and your commands. The folder is ignored by git and safe to delete. chapterjs sync writes them without starting the bot. Projects created with create chapterjs run it after each install, so your editor knows the types right away. To check the types of your whole project from a terminal, use the typecheck script of your project:
It runs tsc -b. A plain tsc checks nothing in a ChapterJS project: your files are checked by the projects of .chapterjs/, which only tsc -b and your editor follow.

While the bot runs

The connection to Discord is kept alive by the framework. When it drops, the bot reconnects by itself and your files keep running:
An error in one of your functions is shown with the file and the line, and stops nothing else: see when your function fails. The bot also looks after its own memory: see Memory.

A new version of ChapterJS

Once the bot is online, chapterjs dev tells you when a newer version of the package is out, with the command that installs it, written for the package manager of your project:
npm is asked at most once a day, after the bot is online, and never holds it: without internet, the line does not appear. Nothing is installed for you: run the command when you want, then start chapterjs dev again.

Stopping

Press Ctrl+C. The bot disconnects properly and goes offline at once:
A second Ctrl+C, a second later, stops the process without waiting; Discord then keeps the bot shown online until it notices the connection is gone.

chapterjs build

Check your bot and compile it for production.

Troubleshooting

Every message, and what to do about it.