What changes from dev
The production application
Remember the second application from Your Discord application? This is where it comes in. On the Bot page of the production application:- Reset Token and copy it. It goes on the machine, never on your computer.
- Enable the same Privileged Gateway Intents as on the dev application: your files are the same, so they need the same ones.
chapterjs startlists what is missing, but in production it stops instead of waiting.
chapterjs start runs in every server and has no reason to print one: in the Developer Portal, OAuth2 → URL Generator, tick bot and applications.commands, pick the permissions your bot needs, and share the link. Give it only what your files use: people trust a bot that asks for little.
Try it on your computer first
Before any machine, run production once locally, to see it work. In the.env of your project, put the production token in place of the dev one for a minute, build, and start:
where: 'dm' files you could not try in dev work now. Stop it with Ctrl+C, and put the dev token back in .env.
chapterjs start only needs BOT_TOKEN. When DEV_GUILD_ID is also there,
production ignores that server, so that a dev bot and a production bot sharing
one token never answer twice. With two applications you do not need that, and
the machine only gets the token.On the machine
A machine that stays on is a server you rent, a container, or a host made for Node applications. The steps are the same everywhere:1
Put the project there
Clone your repository, or copy the folder without
node_modules and
.chapterjs (both are made on the machine). The machine needs Node.js 24
or newer and your package manager.2
Install
The install command of your package manager, in the folder. It also writes
the types of the project.
3
Give it the token
Set
BOT_TOKEN the way the machine does it: an environment variable, the
“secrets” of a host, or a .env file in the folder. The real environment
wins over the file. This is the token of the production application.4
Build, then start
The
build script, then the start script. Many hosts ask for a “build
command” and a “start command”: give them these two.Keeping it running
chapterjs start runs until it is stopped. Two things end it:
- A stop asked by the machine (
Ctrl+C, or the host stopping the process): the bot disconnects cleanly, prints✓ Disconnected, and exits with code 0. Give it a few seconds before killing it. - Something to fix: a refused token, a privileged intent not enabled, no build. The message says what, and the command exits with code 1.
chapterjs start, nothing needs your help: the connection is kept alive and reconnected when it drops, and a large bot’s processes are started again when one stops.
Updating the bot
Put the new files on the machine, build, start again. Until you build, the running bot keeps the previous build, andchapterjs start reminds you:
When the bot grows
Discord splits large bots into several connections, called shards, and ChapterJS opens them by itself. With many of them, it also spreads them over several processes, so the bot uses every CPU of the machine; you see it in the first line:Recap
- Production is the second application: its token goes on the machine, its intents are enabled by hand, its invite link is made in the Developer Portal.
- On the machine: install, set
BOT_TOKEN, build, start; a host takes the two scripts as its build and start commands. - Exit code 0 is a clean stop, 1 is something to fix; let the machine restart the bot, never in a tight loop.
- Updating is building and starting again.
What's next
A checklist, and where to go from here.
Guide: Deploy
The same steps, with every variable and message.