Skip to main content
Everything that can receive a message has a send(): a channel, a user, a member, a webhook. A message is a text, or an object with everything it contains.
src/commands/announce.ts
That is all: channel is the channel the command was used in, and send() posts there. The message is checked before it leaves (a text over 2000 characters, too many embeds…): a mistake is an error in your code with a plain message, not a refusal of Discord.
Every field a message takes is in Message options, and everything a message you receive has is in Message.

Where a message goes

They all take the same thing. A text:
Or an object, when the message has more than a text, or is sent differently:
A message needs at least a content, an embed, a file, a component, a sticker or a poll. Everything else is optional, and every send() returns the Message that was sent, so you can react to it, pin it or edit it later.

Replying

message.reply() answers a message in its channel: Discord shows the message it answers above yours.
A reply notifies the author of the message by default. To answer without pinging, pass allowedMentions:
send() can reply too: pass the message (or its id) as replyTo.

Embeds

An embed is a box with a title, a description, fields, an image, a footer… Pass up to 10 in embeds:
Discord limits what an embed holds (256 characters for a title, 25 fields, 6000 characters for all the embeds of a message…). Going over one throws before anything is sent, with the field and the limit in the message:
The limits are listed in Embed limits.

Files

The pictures and documents your bot sends live in the public/ folder of your project, next to src/. asset() picks one: your editor lists every file of the folder as you type, and a path that does not exist is underlined.
src/commands/chart.ts
The file is read when the message is sent, never before. A file sent under another name takes name; spoiler: true hides it until it is clicked. Two files of one message can’t have the same name: Discord tells them apart by it. In chapterjs dev, a file added to public/ is offered by the editor right away:
A file made by your code (a chart drawn on the fly, a text) is given with its content: a text, a Buffer, a Uint8Array, an ArrayBuffer or a Blob. Up to 10 files per message, from public/ or made, together. A text too long for a message can go in a file instead:

Mentions

A mention is a text: write it in content with the helpers of ChapterJS, or with what a structure gives when put in a text (${member}, ${channel}, ${role}).
By default a message notifies everyone it mentions, roles and @everyone included. allowedMentions says who really gets a notification, whatever the text contains:
  • parse is the kinds of mentions of the text that notify: ['users'], ['roles'], ['everyone'], or [] for nobody.
  • users and roles list the ids that may be notified, whatever parse says.
The helpers (userMention, roleMention, channelMention, timestamp…) are listed in Helpers.

Polls

A poll is a question with up to 10 answers. People vote in Discord; the poll closes after duration hours (24 by default).

Editing

message.edit() changes a message the bot wrote: its text, its embeds, its components, its files, and whether the previews of its links show. Only what you pass changes.
A message written by someone else can’t be edited. What edit() accepts is listed in MessageEditOptions.

Deleting

message.delete() deletes one message; the reason goes to the audit log of the server.
To delete many at once, channel.bulkDelete() takes messages or ids and returns how many were deleted. Discord refuses to delete messages older than two weeks in bulk: they are left out.

Reacting

message.react() adds a reaction of the bot: a standard emoji, or a custom emoji of the server, as Discord writes it (<:name:id>) or as one of guild.emojis.
message.reactions lists the reactions a message has, with how many of each; fetchReactionUsers() asks who reacted with one emoji. removeReaction() removes the reaction of the bot (or of a given user), clearReactions() removes every reaction, or every reaction of one emoji.

Pinning

message.pin() and message.unpin() pin and unpin a message in its channel; channel.fetchPins() lists the pinned messages, latest pin first.

Reading the history

channel.fetchMessages() asks Discord for the latest messages of a channel, newest first, 100 at most per call. before, after and around pick where to read from, so you can go further back:
channel.fetchMessage(id) gets one message by its id. channel.messages is what the bot remembers of the channel without asking Discord: it is empty by default, since most bots never read an old message. See what the bot remembers.
A message you receive in an event is already a Message: no need to fetch it to reply, react or delete.

Buttons, menus and layout

A message can hold buttons and select menus, declared with button() and select(), which run your code when they are used, and be built out of texts, sections, galleries and containers instead of a text and embeds:
src/commands/vote.ts
src/components/yes.ts
components only takes what ChapterJS made, never JSON: the ids that tell a click apart are written by the framework. How to write them is in Buttons, Select menus, Forms and Embeds and layout.

Events about messages

React when a message is sent, edited or deleted.

Message options

Every field a message takes, with the limits.