What you will build
Along the way, you write a small bot for a community server. By the end, it:- answers slash commands like
/diceand/whois, with options people fill in; - welcomes new members and keeps an eye on messages;
- shows buttons, select menus and forms, and reacts when people use them;
- posts a report by itself every morning;
- speaks English and French, depending on who reads it;
- runs on a machine that stays on, for every server that adds it.
Who this is for
You, if one of these is true:- You want a bot for your server and you have never written one.
- You know JavaScript (variables, functions,
asyncandawait) and want to use it for something real. - You have used another Discord library and want to understand how ChapterJS thinks, without reading its reference first.
How to read it
Every chapter has the same shape:- What you are about to do, and why. A bot has moving parts; knowing why a step exists is what lets you remember it.
- A complete file that works as is. Copy it into your project, save, and try it in your test server. Nothing is left as an exercise.
- Points of attention. The mistakes everyone makes once, and what the bot tells you when you make them.
- A recap.
This tutorial links to both when a detail is worth it. You never need them to follow along.
Commands you type in a terminal are shown for the four package managers (pnpm,
npm, yarn, bun). Pick the tab of the one you use, and keep using it: mixing
two in one project causes confusing errors.
Where to start
If you have nothing yet, start with the next page, which explains what a bot is and how it talks to Discord. If you already have a Discord application and a test server, you can go straight to Creating the project; the explanations you skip are short, and you can come back to them.How a bot works
What a bot is, and what happens between Discord and your program.
The tools
Node.js, a package manager, an editor: install and check them.