> ## Documentation Index
> Fetch the complete documentation index at: https://www.chapterjs.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Create a bot, run it on your test server and change its first command, in a few minutes

You need [Node.js](https://nodejs.org) 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](https://www.chapterjs.org/setup/discord-application.md) 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:

```bash pnpm theme={"theme":{"light":"github-light","dark":"vesper"}}
pnpm create chapterjs
```

```bash npm theme={"theme":{"light":"github-light","dark":"vesper"}}
npm create chapterjs@latest
```

```bash yarn theme={"theme":{"light":"github-light","dark":"vesper"}}
yarn create chapterjs
```

```bash bun theme={"theme":{"light":"github-light","dark":"vesper"}}
bun create chapterjs
```

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](https://www.chapterjs.org/setup/project-structure.md#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.

> [!TIP]
>
> 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:

```bash .env theme={"theme":{"light":"github-light","dark":"vesper"}}
BOT_TOKEN=
DEV_GUILD_ID=
```

* `BOT_TOKEN`: the token of your bot, from the **Bot** page of your application in the [Developer Portal](https://discord.com/developers/applications). Use a **dev application**, not the one that will go online for everyone: see [Your Discord application](https://www.chapterjs.org/setup/discord-application.md).
* `DEV_GUILD_ID`: the ID of your test server.

Where to find both is in [Your Discord application](https://www.chapterjs.org/setup/discord-application.md).

> [!WARNING]
>
> Your token is a password: never share it, and never commit `.env`. The project already ignores it in git.

**3. Run it**

```bash pnpm theme={"theme":{"light":"github-light","dark":"vesper"}}
pnpm dev
```

```bash npm theme={"theme":{"light":"github-light","dark":"vesper"}}
npm run dev
```

```bash yarn theme={"theme":{"light":"github-light","dark":"vesper"}}
yarn dev
```

```bash bun theme={"theme":{"light":"github-light","dark":"vesper"}}
bun dev
```

Your bot connects to your test server:

```text theme={"theme":{"light":"github-light","dark":"vesper"}}
✓ Connected to My Server as my-bot
ℹ Intents computed from your files: GUILDS
✓ a presence loaded
```

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](https://www.chapterjs.org/run/dev.md).

**4. Try your first command**

Create a file for your first command, `src/commands/ping.ts`:

```ts src/commands/ping.ts theme={"theme":{"light":"github-light","dark":"vesper"}}
import { command } from 'chapterjs';

export default command({
  name: 'ping',
  description: 'Replies with Pong!',
  async run({ interaction }) {
    await interaction.reply('Pong!');
  },
});
```

Save it: the file is loaded, and the command sent to your test server:

```text theme={"theme":{"light":"github-light","dark":"vesper"}}
↻ Reloaded in 12 ms, 1 command, a presence loaded
↻ Commands updated on My 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](https://www.chapterjs.org/setup/project-structure.md).

When your bot is ready for everyone, put it on a machine that stays on: see [Deploy](https://www.chapterjs.org/run/deploy.md).

> [!NOTE]
>
> Everything the `chapterjs` command does is in the [CLI reference](https://www.chapterjs.org/reference/cli.md).

> [card] [Project structure](https://www.chapterjs.org/setup/project-structure.md)
>
> What each folder and file of your project is for.

> [card] [Commands](https://www.chapterjs.org/commands.md)
>
> A slash command, options typed for you.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.