Skip to main content
A bot is a Discord application with a bot account. You create it in the Developer Portal, and chapterjs dev needs two things from it: the token of the bot and the ID of the server you test in.
Create two applications from the start: one for development, one for production. Name them after your bot, with “dev” in the name of the first (my-bot dev, my-bot). The token of the dev one goes in the .env of your computer, the token of the other one on the machine that will host your bot. A command for everyone belongs to the bot, not to a server, so 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. Why in detail: A second bot for development.
1

Create the application

Open the Developer Portal, click New Application and give it a name: it is the name people see. Do it twice, once for the dev bot and once for the production bot.Then open the Bot page of the application. This is where the bot account of your application lives: its username, its avatar and its token.
2

Copy the token

On the Bot page of the dev application, click Reset Token and copy the token it shows. Discord shows a token once: if you lose it, reset it again, which makes the old one stop working everywhere it was used.Put it in the .env file of your project:
.env
The token is the password of your bot: whoever has it controls the bot. Never share it, never put it in your code, and never commit .env. A project made with create chapterjs already ignores it in git.
3

Copy the ID of your test server

Your test server is where chapterjs dev runs your bot. Any server you manage works: create one for your bot if you don’t have one.Server IDs are hidden until you enable Developer Mode in Discord: Settings → Advanced → Developer Mode. Then right-click your server and choose Copy Server ID. The ID is a number of 17 to 20 digits. Put it in DEV_GUILD_ID.
4

Add the bot to your test server

Nothing to find: run your bot, and chapterjs dev prints the link when the bot is not in the server yet.
Open the link, confirm, and the command goes on by itself:
The link adds the bot to that server only, with every permission (permissions=8 is Administrator): a test server is a playground. It also asks for the applications.commands scope, which lets the bot have slash commands there.
That is all: run chapterjs dev and your bot is online in your test server. The rest of this page is about the three options of the Bot page that some files need.
What chapterjs dev reads from .env, and in which order, is in the CLI reference.

Privileged intents

Discord only sends a bot what it asked for, and three things have to be enabled by hand, under Privileged Gateway Intents on the Bot page of your application: Presence Intent, Server Members Intent and Message Content Intent. You never list them in your code: ChapterJS works out what your files need, and asks you to enable an option only when a file needs it. When a file needs an option that is not enabled, chapterjs dev says which files and gives the link to the page, then waits:
Enable the option, click Save Changes, and the command goes on:
With several options missing, the message lists them all, and the files that need each one:
The same check runs when a file you save while the bot runs needs a new option: the bot reconnects by itself once the option is enabled. See chapterjs dev.
chapterjs dev only waits when it runs in a terminal. Started by another program, and in production with chapterjs start, the same message is an error (✗) and the command stops.
A bot in 100 servers or more has to be verified by Discord to keep its privileged intents. Until then, the options can be enabled freely on the Bot page.

When something is wrong with a value

Each value of .env is checked before anything is tried, and every problem is printed at once, with how to fix it:
A token Discord does not recognize is refused at the first request:
Every message is listed in Troubleshooting.

Project structure

What each folder and file of your project is for.

chapterjs dev

Run your bot on your test server while you write it.