Skip to main content
You need Node.js 24 or newer, a Discord application with a bot, and a server to test in. If you don’t have the application yet, Your Discord application shows how to create one: it takes two minutes and gives you the two values of step 2.
1

Create the project

Run the command for your package manager:
It asks you up to three questions:
  1. Where to create the project: a folder name like my-bot, or . for the current folder. The folder must be new or empty.
  2. Which package manager to use: only the ones installed on your computer can be picked, and the one you ran the command with is selected by default.
  3. Which template to start from: minimal, a presence and nothing else, is preselected. The others are complete bots: see Templates.
A question with only one possible answer is skipped: with a single package manager installed, it is used and you are told so.The template is copied, the dependencies are installed, and the next steps are printed.
Pass the folder name to skip the first question: pnpm create chapterjs my-bot. pnpm create chapter does the same: it is a short alias of the same command.
2

Give it your bot

In the new folder, copy .env.example to .env and fill in the two values:
.env
  • BOT_TOKEN: the token of your bot, from the Bot page of your application in the Developer Portal. Use a dev application, not the one that will go online for everyone: see Your Discord application.
  • DEV_GUILD_ID: the ID of your test server.
Where to find both is in Your Discord application.
Your token is a password: never share it, and never commit .env. The project already ignores it in git.
3

Run it

Your bot connects to your test server:
The presence is the one file of the template, src/presence.ts: what Discord shows under the name of your bot.If the bot is not in your test server yet, the command prints a link that adds it there and waits for you. If one of your files needs an option that is not enabled for your bot, it says which one and where to enable it, and waits too. Every message says what to do: see chapterjs dev.
4

Try your first command

Create a file for your first command, src/commands/ping.ts:
src/commands/ping.ts
Save it: the file is loaded, and the command sent to your test server:
Type /ping in your test server: the bot answers “Pong!”. Change the answer, save, and use /ping again: it answers with the new text.
That is all. name is the name of the command, 'ping' is /ping, and nothing registers it. ChapterJS finds the declaration in your files, tells Discord about the command and runs run when someone uses it. To add a command, declare one with command() and export it, in any file of src/. To react to something that happens on Discord, declare an event() the same way. How the framework finds them is in Project structure. When your bot is ready for everyone, put it on a machine that stays on: see Deploy.
Everything the chapterjs command does is in the CLI reference.

Project structure

What each folder and file of your project is for.

Commands

A slash command, options typed for you.