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:
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
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.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:
A value of .env is wrong
A value of .env is wrong
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.The token is refused
The token is refused
Discord does not recognize the token, usually because it was reset. The command stops.
The bot is not in your test server
The bot is not in your test server
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.
A privileged intent is not enabled
A privileged intent is not enabled
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: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:
⚠ 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: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.↻ Commands updated on My Server. When Discord refuses what your files declare, the bot keeps running with the commands Discord already has:
Only your test server
In dev, your bot only sees the server ofDEV_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:
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: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:
chapterjs dev again.
Stopping
PressCtrl+C. The bot disconnects properly and goes offline at once:
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.