1
Create the project
Run the command for your package manager:It asks you up to three questions:
- Where to create the project: a folder name like
my-bot, or.for the current folder. The folder must be new or empty. - 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.
- Which template to start from:
minimal, a presence and nothing else, is preselected. The others are complete bots: see Templates.
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.
3
Run it
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, Save it: the file is loaded, and the command sent to your test server:Type
src/commands/ping.ts:src/commands/ping.ts
/ping in your test server: the bot answers “Pong!”. Change the answer, save, and use /ping again: it answers with the new text.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.