Skip to main content
Small functions and types exported by chapterjs to write messages and work with ids and images.
How to send what they produce is in the Messages guide; everything a message can contain is in Message options.

Mentions

A structure put in a text becomes its mention: ${user} is <@id>, ${channel} is <#id>, ${role} is <@&id>. When you only have an id, use these functions. They build text; Discord turns it into a mention when the message is shown.

userMention()

<@USER_ID>: mentions a user.

channelMention()

<#CHANNEL_ID>: links a channel.

roleMention()

<@&ROLE_ID>: mentions a role.

commandMention()

</NAME:COMMAND_ID>: a clickable slash command. The name includes the subcommand group and subcommand when there are some ("foo group bar").

emojiMention()

<:NAME:ID> or <a:NAME:ID>: a custom emoji.

GuildNavigation

Guild Navigation Types: links to a tab of the current server. Put the value in a message as it is. Discord documentation

Dates

timestamp()

<t:TIMESTAMP> or <t:TIMESTAMP:STYLE>: a date shown to each reader in their own timezone and language. Timestamps are expressed in seconds. A number is milliseconds since the Unix epoch, like Date.now(). Something that is not a date throws a TypeError:

TimestampStyle

How timestamp() is shown. Without a style, Discord uses LongDateShortTime. Discord documentation

Ids

Snowflake

A Discord id: a 64-bit number serialized as a string.
Every id is one, and every option that takes an id takes a Snowflake. It is text because the number is too big for a JavaScript number: never turn it into one.

isSnowflake()

Whether a value looks like a Discord id: used to reject a wrong value (a name, a mention, a number) before it is sent to Discord.

snowflakeTimestamp()

When the thing a snowflake identifies was created, in milliseconds since the Unix epoch: (snowflake >> 22) + 1420070400000. Structures already have createdAt; this is for an id alone.

snowflakeFromTimestamp()

The smallest snowflake created at a given time: lets before / after pagination start from a date.
A date before Discord existed throws a RangeError:
Discord documentation

Images

ImageOptions

What every method that ends with URL takes: user.avatarURL(), member.avatarURL(), guild.iconURL(), guild.bannerURL(), guild.splashURL(), role.iconURL(), emoji.url()…
ImageFormat
The file format. By default: WebP, which Discord recommends since it works for still and animated images, whatever was uploaded.
ImageSize
The size in pixels: a power of two between 16 and 4096.
boolean
false to get the first frame of an animated image. By default an animated image stays animated.
What you get follows a few rules:
  • Asking for 'gif' on an image that is not animated gives a PNG instead.
  • An animated image stays animated only in WebP (the default) or GIF; animated: false gives its first frame.
  • A wrong value throws a RangeError before any URL is built:

ImageFormat

ImageSize

Image size can be any power of two between 16 and 4096.
Discord documentation