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

# Overview

> Find every property and method of what your functions receive: servers, members, channels, messages

ChapterJS gives your code **structures**: a server, a member, a channel, a message... Each one has properties to read and methods to act. Everything is typed, so your editor completes names and underlines mistakes before the bot runs. You never create a structure: your [commands](https://www.chapterjs.org/commands.md), your [events](https://www.chapterjs.org/events.md) and your [components](https://www.chapterjs.org/components.md) receive them.

> [!NOTE]
>
> This tab lists everything. How to write a bot with it is in the guide, starting with the [quickstart](https://www.chapterjs.org/quickstart.md).

## The structures

> [card] [Guild](https://www.chapterjs.org/reference/guild.md)
>
> A server: its members, roles, channels, bans.

> [card] [GuildMember](https://www.chapterjs.org/reference/member.md)
>
> A user in one server: nickname, roles, permissions, moderation.

> [card] [User](https://www.chapterjs.org/reference/user.md)
>
> A Discord account, the same in every server.

> [card] [Role](https://www.chapterjs.org/reference/role.md)
>
> A role of a server: permissions, position, members.

> [card] [Channels](https://www.chapterjs.org/reference/channels)
>
> Text, voice, category, forum, thread and private channels.

> [card] [Message](https://www.chapterjs.org/reference/message.md)
>
> A message: reply, edit, react, pin.

> [card] [Interaction](https://www.chapterjs.org/reference/interaction.md)
>
> Someone used a command, a button, a menu or a form, and waits for an answer.

> [card] [GuildEmoji](https://www.chapterjs.org/reference/emoji.md)
>
> A custom emoji of a server.

> [card] [Invite](https://www.chapterjs.org/reference/invite.md)
>
> An invite to a server.

> [card] [Webhook](https://www.chapterjs.org/reference/webhook.md)
>
> A way to post in a channel under any name.

What your files are written with is on its own pages: [command()](https://www.chapterjs.org/reference/command.md), [event()](https://www.chapterjs.org/reference/event.md) and [every event](https://www.chapterjs.org/reference/events.md), [button()](https://www.chapterjs.org/reference/button.md), [select()](https://www.chapterjs.org/reference/select.md), [modal()](https://www.chapterjs.org/reference/modal.md), [embed()](https://www.chapterjs.org/reference/embed.md), the [layout](https://www.chapterjs.org/reference/layout.md) of a message and [task()](https://www.chapterjs.org/reference/task.md). Shared types have one page each: [message options](https://www.chapterjs.org/reference/message-options.md), [options](https://www.chapterjs.org/reference/options.md), [data](https://www.chapterjs.org/reference/data.md), [permissions](https://www.chapterjs.org/reference/permissions.md), [enums](https://www.chapterjs.org/reference/enums.md), [helpers](https://www.chapterjs.org/reference/helpers.md) and [errors](https://www.chapterjs.org/reference/errors.md).

## Three rules

**1. A property never costs anything**

`guild.name`, `member.roles`, `guild.channels`... read what the bot remembers. They are instant and never send a request to Discord.

**2. A fetch method asks Discord**

Methods that start with `fetch` return a promise. When they get one thing by its id, they look at what the bot remembers first and only ask Discord when it is not there. Pass `{ force: true }` to ask Discord anyway.

**3. Other methods act**

`member.ban()`, `channel.send()`, `message.delete()`... do something on Discord and return a promise. Always `await` them.

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
import type { Guild } from 'chapterjs';

async function example(guild: Guild) {
  console.log(guild.name, guild.roles.size); // instant
  const owner = await guild.fetchOwner(); // remembered, or else asked to Discord
  await owner.send(`Hello from ${guild.name}!`); // done on Discord
}
```

## Names are in camelCase

Discord names its fields like `rate_limit_per_user`. In ChapterJS you always read and write `rateLimitPerUser`: the framework translates in both directions, inside embeds and options too.

## Lists are Maps

`guild.members`, `guild.roles`, `guild.channels`, `channel.messages`... are JavaScript [`Map`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)s that you can only read, with the id as the key:

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
import type { Guild } from 'chapterjs';

function example(guild: Guild) {
  const role = guild.roles.get('123456789012345678');
  const names = [...guild.channels.values()].map(channel => channel.name);
  return { role, names };
}
```

What a `Map` holds is what the bot remembers, which is not always everything: see [Memory](https://www.chapterjs.org/memory.md).

## Ids

A Discord id (a `Snowflake`) is a text made of digits, like `'175928847299117063'`. Never store one as a number: it is too big and would lose precision.

Everywhere a method takes a user, a role, a channel or a message, you can pass its id or the structure itself.

## The reason

Actions that moderators can see in the audit log of the server take a `reason`, shown there:

```ts theme={"theme":{"light":"github-light","dark":"vesper"}}
import type { GuildMember } from 'chapterjs';

async function example(member: GuildMember) {
  await member.kick('Spamming invite links');
  await member.ban({ reason: 'Raid', deleteMessageSeconds: 3600 });
}
```

## Limits are checked for you

What you pass is checked before it is sent: a message that is too long, an image size that does not exist or a timeout of more than 28 days throws an error that says what the limit is. The rate limits of Discord are handled by the framework: a request waits for its turn.

When Discord refuses an action (a missing permission, something that no longer exists...), the method throws: see [Errors](https://www.chapterjs.org/reference/errors.md).

## Logging

`console.log(guild)` shows the name of the class and the data of the structure with camelCase names. `toJSON()` returns that data as a plain object. Neither shows a secret: a [webhook](https://www.chapterjs.org/reference/webhook.md) leaves its token out.


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