> ## 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.

# ChapterJS

> The Discord framework. A folder of files becomes a fast, type-safe Discord bot.

[0.5.1
Five new templates to start from](https://www.chapterjs.org/setup/project-structure.md#templates)

# The Discord framework

A folder of files becomes a fast, type-safe Discord bot. Nothing to configure, nothing to register, nothing to install to run it.

```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
```

[Get started ](https://www.chapterjs.org/quickstart.md)

[ GitHub](https://github.com/chapterjs/chapterjs)

my-bot

Explorer

src

commands

ping.ts

poll.ts

components

vote.ts

events

welcome.ts

.env

package.json

&#x20;src/commands/ping.ts

1
import{ command }from'chapterjs';

2



3
&#x20;   export defaultcommand(\{



4
name: 'ping',

5
description: 'Replies with Pong!',



6
&#x20;   asyncrun(\{ interaction }) \{



7
await interaction.reply('Pong! Nice shot 🏓');

8
},

9
});

&#x20;Terminal

\$ pnpm dev✓ Connected to My Server as my-botℹ Intents computed from your files: GUILDS, GUILD\_MEMBERS✓ 2 commands, 1 event, 1 component loaded↻ Reloaded in 12 ms, 2 commands, 1 event, 1 component loaded

\$

\# bot-testing

Alex

Today at 14:02

used /ping

My Bot
APP
Today at 14:02

Pong!

Alex

Today at 14:03

used /ping

My Bot
APP
Today at 14:03

Pong! Nice shot 🏓

Message #bot-testing

0

dependencies to run a bot

100%

type-safe, no `any`

v10

Discord API and gateway

1

command to start

How it feels

## The export is the API

What a file exports says what it is. A command has its name, an event has its name, a button is named by its export, and the same import works in every file. Nothing is registered, nothing is annotated.

```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!');
  },
});
```

```ts src/events/welcome.ts theme={"theme":{"light":"github-light","dark":"vesper"}}
import { event } from 'chapterjs';

export default event({
  name: 'memberJoin',
  async run({ member, guild }) {
    await member.send(`Welcome to ${guild.name}!`);
  },
});
```

That is all. `/ping` is registered on Discord, the bot asks for the Server Members intent because a declaration needs it, and `member` and `guild` are typed from `name`, without you writing a type.

What you get

## Everything a bot needs, nothing to set up



command(\\\{ name: 'ping' \\})


&#x20;      &#x20;

command(\\\{ name: 'poll' \\})


&#x20;      &#x20;

event(\\\{ name: 'memberJoin' \\})


&#x20;      &#x20;

export const vote = button(...)


&#x20;    &#x20;
&#x20;    &#x20;

/ping


&#x20;      &#x20;

/poll


&#x20;      &#x20;

on member join


&#x20;      &#x20;

a button


&#x20;  &#x20;

\### Exports are the API


&#x20;    &#x20;

\`event(\{ name: 'memberJoin' })\` runs when someone joins. \`command(\{ name: 'ping' })\` shows up as a slash command. \`export const vote = button(...)\` is a button, with an id you never write. Put them in the files you like: no client, no registration script, no list of intents.



save

live

### Instant hot reload

`chapterjs dev` reloads every file you save, and the files they import. A broken file never crashes the bot: its last working version keeps running.

options.targt

✗ Property 'targt' does not exist. Did you mean 'target'?

### Type-safe end to end

What your function receives is typed from where the file is and what it declares: command options, the member of an event, the channel of a message. Mistakes are underlined before the bot runs.

GUILDS

GUILD\_MESSAGES

GUILD\_MEMBERS

MESSAGE\_CONTENT

### Intents computed for you

Worked out from your files, never listed by hand. A privileged one is named with the files that need it and a link to the Developer Portal page to enable it.

What happened

What to do

### Errors in plain words

A missing token, a bot not in your server, a permission the bot lacks: every message says what happened, then what to do, with the file and line when it is yours.

### Nothing to install to run

Only Node.js built-ins and native TypeScript. Fast startup, low memory, and no request to Discord when the bot already knows the answer.

### Discord's limits, handled

Rate limits, payload sizes and the size of what you send are checked and queued by the framework. You never write a retry.

### Clean shutdown

Ctrl+C or SIGTERM closes the Discord session properly, so your bot goes offline at once and no ghost stays online.

Quickstart

## Online in three steps

01

### Create

Run `pnpm create chapterjs`, pick a folder and a template. Dependencies are installed for you.

02

### Configure

Put `BOT_TOKEN` and `DEV_GUILD_ID` in `.env`. Anything missing is explained before the bot connects.

03

### Run

Start `pnpm dev`. Your bot joins your test server and reloads every time you save.

CLI

## One CLI, from the first test to production

The same project runs while you write it and once it is online. A dev process and a production process can even share one bot token: dev only sees your test server, production ignores it.

chapterjs dev
development

<ul>
  <li>Runs on your test server only</li>

  <li>Reloads every file you save</li>

  <li>A broken file keeps its last working version</li>

  <li>Errors shown with the file and line</li>
</ul>

chapterjs start
production

<ul>
  <li>Runs what `chapterjs build` checked and compiled</li>

  <li>Commands registered for everyone</li>

  <li>Several processes for a large bot, by itself</li>

  <li>Ignores your test server</li>
</ul>

## Your bot is one command away.

Create a project, add your token, and run it on your test server.

[Read the quickstart ](https://www.chapterjs.org/quickstart.md)

[ Star on GitHub](https://github.com/chapterjs/chapterjs)


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