Create the project
Open a terminal in the folder where you keep your projects, and run the command of your package manager:- Where to create the project. A folder name, like
buddy. The folder must not exist yet, or be empty. (.means “right here”, for a folder you already created.) - Which package manager to use. Only the ones installed on your computer can be picked, and the one you ran the command with is preselected: press Enter.
- Which template to start from. Take
minimal, preselected: one file, enough to see the bot online, and this tutorial adds the rest. The others (tickets,moderation,levels,giveaways) are complete bots to read once you know the framework: see Templates.
ℹ. You will see that habit everywhere.
Move into the folder and open it in your editor:
Give it your bot
The project has a file called.env.example:
.env.example
.env (same folder, without .example), and fill in the two values from the previous page: the token after BOT_TOKEN=, the server ID after DEV_GUILD_ID=, no quotes, no spaces.
Why two files? .env.example is committed to git and shows what the project needs, with empty values. .env holds the real values and is ignored by git (look at .gitignore: it is already there). That way, your token never ends up in a repository, even a private one, and whoever gets the project knows what to fill in.
Run it
Reading the terminal
Each line of that output tells you something, and the symbol in front says what kind:
Now the lines, one by one:
✓ Connected to My Server as buddy: the program logged in with your token, and found your test server. “My Server” is the name of the server ofDEV_GUILD_ID.ℹ Intents computed from your files: GUILDS: the intents of the previous chapter. The framework read your files and asked Discord for what they need.GUILDSis the one every bot needs to know its servers; nothing in the template needs more.✓ a presence loaded: the files ofsrc/were read: one presence, and nothing else yet. It is the one file of the template,src/presence.ts, and it is why “Getting ready” shows under the name of the bot. Commands, events, buttons, languages: each is a chapter of this tutorial.
Stopping
PressCtrl+C in the terminal. The bot disconnects properly and goes offline at once:
Ctrl+C kills the program without saying goodbye, and Discord then keeps the bot shown online for a while, until it notices that nobody is on the line.
When something is wrong
Every value of.env is checked before anything else, and every problem is printed at once with what to do:
Recap
pnpm create chapterjs(or the command of your package manager) creates the project and installs it..envholdsBOT_TOKENandDEV_GUILD_ID, and git ignores it.pnpm devruns the bot on your test server; the first time, a link adds the bot there.- The symbol of each line says what kind of message it is;
✗always comes with what to do. Ctrl+Conce, then wait for✓ Disconnected.
A tour of the project
What each file is for, and the rule behind all of them.
Guide: Quickstart
The same steps on one page.