On This Page

Builders and Formatting

34 symbols from @neontechspace/fluxerly

Variables#

AssetFormats#

Choose the image format for an asset URL

WebP is the default. Sticker URLs do not accept this choice

const AssetFormats: Readonly<{ … }>
Apng#

Animated PNG image, can preserve animation

"apng"
Gif#

GIF image, can preserve animation

"gif"
Jpeg#

Static JPEG image, use animated false for an animated source

"jpeg"
Png#

Static PNG image, use animated false for an animated source

"png"
Webp#

WebP image, supports static images and animation

"webp"

TimestampStyles#

Choose how Fluxer displays a timestamp in a message

The viewer's locale and timezone control its rendered text

const TimestampStyles: Readonly<{ … }>
LongDate#

Written-out date

"D"
LongDateTime#

Written-out date and time

"F"
LongTime#

Time including seconds

"T"
RelativeTime#

Time relative to the viewer's current time, such as "a few minutes ago"

"R"
ShortDate#

Compact date

"d"
ShortDateMediumTime#

Compact date and time including seconds

"S"
ShortDateShortTime#

Compact date and short time

"s"
ShortDateTime#

Date and time, the default used by format.timestamp

"f"
ShortTime#

Time without seconds

"t"

assets#

Build hosted Fluxer URLs for avatars, banners, community images, emoji and stickers

Calls return the URL, null or undefined directly and throw AssetUrlError for invalid input. They do not download the image or need a client. Use client.instance.resolve() for helpers tied to a self-hosted instance instead. Member avatar and banner helpers read only guildId, userId and the chosen image hash. The displayMemberAvatar helper also reads profileFlags to choose the fallback image

const assets: AssetHelpers

builders#

Start optional chainable builders for embed and message objects

Both package entry points return builders immediately, not lazy Effects

const builders: Readonly<{ … }>
embed#

Return a new empty EmbedBuilder

Call build to get a plain embed object, no message is sent

() => EmbedBuilder
message#

Return a new empty MessageBuilder

Select content, an embed, an attachment or a sticker before building

() => MessageBuilder<false>

colors#

Convert supported RGB numbers, six-digit hex strings and RGB tuples into colors

Invalid input throws HelperError rather than being converted automatically. For colors received from users, tryParse returns a Result instead of throwing. No client or network request is needed

const colors: ColorHelpers

display#

Choose a display name from supplied user or member data

No account request or cache lookup is made

const display: DisplayHelpers

format#

Create Fluxer markup for mentions, timestamps, custom emoji and Markdown escaping

Use these helpers when building message content, without creating a client or making a request. Helpers return plain values and throw HelperError for invalid input, which indicates a programming mistake. For text received from users, tryParseMention, tryParseTimestamp and tryParseCustomEmoji return a Result instead of throwing. Check isOk() before reading value, or isErr() before reading error. A mention in the text does not enable notifications, which are controlled by allowedMentions when sending

const format: FormatHelpers

Build links to Fluxer channels, direct messages, messages and bot installation pages

These helpers use hosted Fluxer URLs. Each helper returns the URL directly, and invalid route inputs throw HelperError. Building a link does not check access or install the bot

const links: LinkHelpers

snowflakes#

Read and convert Fluxer's IDs, called snowflakes, without losing integer precision

Keep IDs as decimal strings rather than JavaScript numbers. Conversions return plain values and throw HelperError for an invalid ID or Date. For IDs received from users, tryParse returns a Result instead of throwing

const snowflakes: SnowflakeHelpers

text#

Split a string into frozen pieces without dropping its text, or truncate it to a length with a marker

Each lone surrogate becomes U+FFFD (�) first. The maxLength option of split and truncate counts UTF-16 code units, as JavaScript string.length does. Cuts fall between visible characters, so a piece or truncated string can be shorter than maxLength. Only split cuts inside a single character, and only one longer than maxLength. Truncate returns the suffix alone when its first character does not fit before the suffix. The pieces or the truncated string are returned directly, and invalid text or options throw HelperError. These helpers neither send the result nor repair Markdown cut by it

const text: TextHelpers

Classes#

EmbedBuilder
Assemble an embed by chaining methods, then pass the builder or build()'s plain object in a message operation's embeds
MessageBuilder
Assemble a message by chaining methods, then send the plain object returned by build()

Interfaces#

AssetUrlOptions#

Choose the format, size and animation to request in an asset URL

Unknown keys or invalid values throw AssetUrlError, even when the target has no image

interface AssetUrlOptions
animated optional#

Request animation or a still image

When omitted, animated asset hashes or emoji metadata select animation. Requesting animation with Png or Jpeg throws AssetUrlError, choose animated false to request a still image instead

boolean
format optional#

Output encoding

Webp is used when omitted

AssetFormat
size optional#

Requested image size in pixels, an integer from 0 through 4_294_967_295

Omit it to leave size selection to Fluxer. The helper sends it unchanged, Fluxer selects a supported size for that asset

number

CustomEmojiMarkup#

Custom-emoji fields used by Fluxer's explicit <:name:id> or <a:name:id> markup

interface CustomEmojiMarkup
animated optional#

Selects <a:...> rather than <:...>

boolean
id#

Decimal Fluxer emoji ID

string
name#

ASCII letters, digits, underscores, or hyphens as accepted by Fluxer's message parser

string

EmbedFieldOptions#

Display settings for one field added with EmbedBuilder.field

interface EmbedFieldOptions
inline optional#

Request side-by-side display with neighboring inline fields

Omit or use false for a full-width field

boolean

InstallationLinkOptions#

Optional raw permission bitfield requested by a hosted bot-installation page

interface InstallationLinkOptions
permissions optional#

Unsigned 64-bit Fluxer permission bitfield

Omit it to leave the provider's requested permissions unspecified

bigint

StickerAssetUrlOptions#

Choose sticker size and animation

There is no format option because Fluxer chooses the sticker encoding. Unknown keys or invalid values throw AssetUrlError

interface StickerAssetUrlOptions
animated optional#

Override the sticker's animated metadata

Animated stickers return their GIF source, other stickers return WebP

boolean
size optional#

Requested size in pixels, an integer from 0 through 4_294_967_295

Omit to leave size selection to Fluxer, the helper does not resize it locally

number

TextSplitOptions#

Choose the largest piece text.split may return

Supply a limit explicitly. This helper does not discover a server's message limit

interface TextSplitOptions
maxLength#

Maximum string.length of each piece, a positive safe integer with no default

Most emoji count as two or more units, and a piece can be shorter when a visible character would otherwise be cut

number

TextTruncateOptions#

Choose where text.truncate cuts and what it appends

Supply the limit explicitly. This helper does not discover a server's message limit

interface TextTruncateOptions
maxLength#

Maximum string.length of the result including the suffix, a positive safe integer with no default

Most emoji count as two or more units, and the result can be shorter when a visible character would otherwise be cut, down to the suffix alone

number
suffix optional#

Text appended after a cut, a well-formed string of at most maxLength units

Defaults to "…" (U+2026). Pass "" for a hard cut

string

TimestampMarkup#

One parsed timestamp markup value

The date field has whole-second precision because Fluxer markup has no milliseconds

interface TimestampMarkup
date#

UTC instant represented by the markup

Date
style#

Explicit style, or Fluxer's default short-date-time style when omitted in the markup

TimestampStyle

Type Aliases#

AssetHelpers#

Methods of the assets helper, which builds image URLs for avatars, banners, community images, emoji and stickers

Each method returns its URL, null or undefined directly and throws AssetUrlError for an invalid target, ID, hash or option

type AssetHelpers = Readonly<{ … }>

avatar#

Build the user's custom-avatar URL, or null when the avatar field is null

Uses only the supplied id and avatar fields, and no profile is fetched. An omitted avatar is invalid and throws AssetUrlError

avatar(
    user: Pick<User, "id" | "avatar">,
    options?: AssetUrlOptions
): string | nullavatar(
  user:
    Pick<User, "id" | "avatar">,
  options?: AssetUrlOptions
): string | null

Parameters

user
Pick<User, "id" | "avatar">
options optional
AssetUrlOptions
Returns
string | null

defaultAvatar#

Build Fluxer's static default-avatar URL from a canonical user ID

Static defaults have no media transform query and do not depend on user-profile availability

defaultAvatar(userId: string): string

Parameters

userId
string
Returns
string

displayAvatar#

Build a URL suitable for displaying a user avatar, using the custom avatar or a static default when avatar is null

Requires known user id and avatar fields. It never produces null, and invalid targets or options throw AssetUrlError

displayAvatar(
    user: Pick<User, "id" | "avatar">,
    options?: AssetUrlOptions
): stringdisplayAvatar(
  user:
    Pick<User, "id" | "avatar">,
  options?: AssetUrlOptions
): string

Parameters

user
Pick<User, "id" | "avatar">
options optional
AssetUrlOptions
Returns
string

displayMemberAvatar#

Choose an avatar to display for a user in a community

The user ID must match member.userId. Normally chooses the member avatar, then the account avatar, then a static default, while AvatarUnset selects the static default directly. Produces undefined if profileFlags is omitted or avatar is omitted without AvatarUnset. Reads guildId, userId, avatar and profileFlags from the member, not banner. Invalid targets or options throw AssetUrlError

displayMemberAvatar(
    user: Pick<User, "id" | "avatar">,
    member: Pick<
        GuildMember,
        "guildId" | "userId" | "avatar" | "profileFlags"
    >,
    options?: AssetUrlOptions
): string | undefineddisplayMemberAvatar(
  user:
    Pick<User, "id" | "avatar">,
  member: Pick<
    GuildMember,
    | "guildId" | "userId"
    | "avatar" | "profileFlags"
  >,
  options?: AssetUrlOptions
): string | undefined

Parameters

user
Pick<User, "id" | "avatar">
member
Pick<GuildMember, "guildId" | "userId" | "avatar" | "profileFlags">Pick<
  GuildMember,
  | "guildId" | "userId" | "avatar"
  | "profileFlags"
>
options optional
AssetUrlOptions
Returns
string | undefined

emoji#

Build a custom-emoji image URL from only its ID and animated metadata, without looking up the emoji

Animated emoji request animation by default. Choose Webp, Gif or Apng to preserve it, or animated false for a still image

emoji(
    emoji: Pick<GuildEmoji, "id" | "animated">,
    options?: AssetUrlOptions
): stringemoji(
  emoji: Pick<
    GuildEmoji, "id" | "animated"
  >,
  options?: AssetUrlOptions
): string

Parameters

emoji
Pick<GuildEmoji, "id" | "animated">
options optional
AssetUrlOptions
Returns
string

guildBanner#

Build a community banner URL from the community's id and banner

An omitted banner hash produces undefined, and an explicitly absent banner produces null

guildBanner(
    guild: Pick<Guild, "id" | "banner">,
    options?: AssetUrlOptions
): string | null | undefinedguildBanner(
  guild:
    Pick<Guild, "id" | "banner">,
  options?: AssetUrlOptions
): string | null | undefined

Parameters

guild
Pick<Guild, "id" | "banner">
options optional
AssetUrlOptions
Returns
string | null | undefined

guildEmbedSplash#

Build the background image URL for an embedded community invite, using id and embedSplash

An omitted embedSplash hash produces undefined, and an explicitly absent one produces null

guildEmbedSplash(
    guild: Pick<Guild, "id" | "embedSplash">,
    options?: AssetUrlOptions
): string | null | undefinedguildEmbedSplash(
  guild: Pick<
    Guild, "id" | "embedSplash"
  >,
  options?: AssetUrlOptions
): string | null | undefined

Parameters

guild
Pick<Guild, "id" | "embedSplash">
options optional
AssetUrlOptions
Returns
string | null | undefined

guildIcon#

Build a community icon URL from the community's id and icon

An omitted icon hash produces undefined, and an explicitly absent icon produces null

guildIcon(
    guild: Pick<Guild, "id" | "icon">,
    options?: AssetUrlOptions
): string | null | undefinedguildIcon(
  guild:
    Pick<Guild, "id" | "icon">,
  options?: AssetUrlOptions
): string | null | undefined

Parameters

guild
Pick<Guild, "id" | "icon">
options optional
AssetUrlOptions
Returns
string | null | undefined

guildSplash#

Build the community's invite-background image URL from id and splash

An omitted splash hash produces undefined, and an explicitly absent splash produces null

guildSplash(
    guild: Pick<Guild, "id" | "splash">,
    options?: AssetUrlOptions
): string | null | undefinedguildSplash(
  guild:
    Pick<Guild, "id" | "splash">,
  options?: AssetUrlOptions
): string | null | undefined

Parameters

guild
Pick<Guild, "id" | "splash">
options optional
AssetUrlOptions
Returns
string | null | undefined

memberAvatar#

Build the member's community avatar URL using only guildId, userId and avatar

Produces undefined for an omitted avatar hash, or null for an explicitly absent avatar. It does not choose a fallback, which displayMemberAvatar provides

memberAvatar(
    member: Pick<GuildMember, "guildId" | "userId" | "avatar">,
    options?: AssetUrlOptions
): string | null | undefinedmemberAvatar(
  member: Pick<
    GuildMember,
    "guildId" | "userId" | "avatar"
  >,
  options?: AssetUrlOptions
): string | null | undefined

Parameters

member
Pick<GuildMember, "guildId" | "userId" | "avatar">Pick<
  GuildMember,
  "guildId" | "userId" | "avatar"
>
options optional
AssetUrlOptions
Returns
string | null | undefined

memberBanner#

Build the member's community banner URL using only guildId, userId and banner

Produces undefined for an omitted banner hash, or null for an explicitly absent banner. It does not substitute the account banner

memberBanner(
    member: Pick<GuildMember, "guildId" | "userId" | "banner">,
    options?: AssetUrlOptions
): string | null | undefinedmemberBanner(
  member: Pick<
    GuildMember,
    "guildId" | "userId" | "banner"
  >,
  options?: AssetUrlOptions
): string | null | undefined

Parameters

member
Pick<GuildMember, "guildId" | "userId" | "banner">Pick<
  GuildMember,
  "guildId" | "userId" | "banner"
>
options optional
AssetUrlOptions
Returns
string | null | undefined

roleIcon#

Build a role icon URL from the role's id and icon

Role icons are never animated. An omitted icon hash produces undefined, and an explicitly absent icon produces null. A role that shows an emoji has no image icon, so read its unicodeEmoji

roleIcon(
    role: Pick<GuildRole, "id" | "icon">,
    options?: AssetUrlOptions
): string | null | undefinedroleIcon(
  role:
    Pick<GuildRole, "id" | "icon">,
  options?: AssetUrlOptions
): string | null | undefined

Parameters

role
Pick<GuildRole, "id" | "icon">
options optional
AssetUrlOptions
Returns
string | null | undefined

sticker#

Build a custom-sticker URL from only its ID and animated metadata

Sticker format is intentionally absent, because Fluxer returns WebP except an animated sticker's GIF source

sticker(
    sticker: Pick<GuildSticker, "id" | "animated">,
    options?: StickerAssetUrlOptions
): stringsticker(
  sticker: Pick<
    GuildSticker, "id" | "animated"
  >,
  options?: StickerAssetUrlOptions
): string

Parameters

sticker
Pick<GuildSticker, "id" | "animated">
options optional
StickerAssetUrlOptions
Returns
string

userBanner#

Build an account-banner URL from a users.fetchProfile result, using only user.id and profile.banner

A null banner stays null, even when a limited profile withheld the banner, so null does not prove that the account has no banner. Uses AssetUrlOptions' WebP default and transform validation, without fetching, selecting a community banner or verifying existence or access

userBanner(
    profile: Readonly<
        {
            profile: Pick<UserProfileFields, "banner">
            user: Pick<User, "id">
        }
    >,
    options?: AssetUrlOptions
): string | nulluserBanner(
  profile: Readonly<
    {
      profile: Pick<
        UserProfileFields, "banner"
      >
      user: Pick<User, "id">
    }
  >,
  options?: AssetUrlOptions
): string | null

Parameters

profile
Readonly<
    {
        profile: Pick<UserProfileFields, "banner">
        user: Pick<User, "id">
    }
>Readonly<
  {
    profile: Pick<
      UserProfileFields, "banner"
    >
    user: Pick<User, "id">
  }
>
options optional
AssetUrlOptions
Returns
string | null

ColorHelpers#

Methods of the colors helper, which converts RGB numbers, hex strings and tuples

Most methods return plain values and throw HelperError for invalid input. The tryParse method accepts untrusted input and returns a Result instead of throwing

type ColorHelpers = Readonly<{ … }>

parse#

Convert a six-digit hexadecimal string, an RGB array of three integer channels from 0 through 255, or a color number to the integer used by embeds and roles

The leading # is optional. CSS names, three-digit shorthand, alpha channels and surrounding whitespace are rejected. Values are never rounded or clamped, and invalid input throws HelperError. For colors received from users, use tryParse, which reports the same HelperError without throwing

parse(value: ColorInput): number

Parameters

Returns
number

toHex#

Turn a color integer into a lowercase six-digit string such as "#000001", including leading zeroes

Accepts only integers from 0 through 0xffffff, not the strings or arrays accepted by parse. Throws HelperError for invalid numbers

toHex(value: number): string

Parameters

value
number
Returns
string

toRgb#

Split a color integer into a new frozen [red, green, blue] array, each from 0 through 255

Accepts only integers from 0 through 0xffffff. Throws HelperError for invalid numbers

toRgb(value: number): RgbColor

Parameters

value
number
Returns
RgbColor

tryParse#

Convert a color with the same rules as parse, but report invalid input without throwing

The default API returns a Result holding the color integer or HelperError. The native API returns an Effect that reads the input when run and fails with HelperError. Use it for colors received from users or other untrusted sources

tryParse(value: ColorInput): Result<number, HelperError>tryParse(
  value: ColorInput
): Result<number, HelperError>

Parameters

Returns
Result<number, HelperError>
Fails with

ColorInput#

A color accepted by colors.parse: A number from 0 through 0xffffff, six hexadecimal digits such as "#ff8800", or [255, 136, 0]

type ColorInput = number | string | RgbColortype ColorInput =
    number | string | RgbColor

DisplayHelpers#

Methods of the display helper, which chooses a display name from supplied user or member data

type DisplayHelpers = Readonly<{ … }>type DisplayHelpers =
    Readonly<{ … }>

name#

Return the member's nickname, otherwise the user's displayName, otherwise username

Only null or undefined trigger a fallback. Supply a member for the same user, this helper does not check identity or fetch data

name(
    user:
        & Pick<User, "username">
        & { readonly displayName?: string | null },
    member?: Pick<GuildMember, "nickname">
): stringname(
  user:
    & Pick<User, "username">
    & {
        readonly displayName?:
          | string | null
      },
  member?:
    Pick<GuildMember, "nickname">
): string

Parameters

user
Pick<User, "username"> & { readonly displayName?: string | null }& Pick<User, "username">
& {
    readonly displayName?:
      | string | null
  }
member optional
Pick<GuildMember, "nickname">
Returns
string

FormatHelpers#

Methods of the format helper, which creates and reads mention, timestamp and custom-emoji markup and escapes Markdown

Most methods return plain values and throw HelperError for invalid input. The try-prefixed parsers accept untrusted text and return a Result instead of throwing

type FormatHelpers = Readonly<{ … }>type FormatHelpers =
    Readonly<{ … }>

channelMention#

Create <#id> text linking to a channel, such as <#123>, and return it directly

Throws HelperError for an invalid decimal-string ID, and no channel lookup occurs

channelMention(id: string): string

Parameters

id
string
Returns
string

customEmoji#

Create <:name:id> text, or <a:name:id> when animated is true

A GuildEmoji can be passed directly. Throws HelperError for invalid names, IDs or animation values. This does not upload or look up an emoji

customEmoji(input: CustomEmojiMarkup): stringcustomEmoji(
  input: CustomEmojiMarkup
): string

Parameters

Returns
string

escapeMarkdown#

Add backslashes so text is treated literally by Fluxer's markup parser, for example escaping **bold**

Returns the escaped string immediately and never throws for string input. It does not change a message's allowedMentions or enable notifications

escapeMarkdown(value: string): string

Parameters

value
string
Returns
string

parseCustomEmoji#

Read exactly one <:name:id> or <a:name:id> string into frozen name, ID and animated fields

Throws HelperError for malformed markup. This does not resolve shortcodes such as :smile: or parse Unicode emoji. For text received from users, use tryParseCustomEmoji, which reports the same HelperError without throwing

parseCustomEmoji(value: string): CustomEmojiMarkupparseCustomEmoji(
  value: string
): CustomEmojiMarkup

Parameters

value
string

parseMention#

Read a string containing exactly one user, role or channel mention into a frozen { kind, id } object

Both <@id> and <@!id> produce kind "user". Throws HelperError for surrounding text, malformed markup or an invalid decimal ID. For text received from users, use tryParseMention, which reports the same HelperError without throwing

parseMention(value: string): Mention

Parameters

value
string
Returns
Mention

parseTimestamp#

Read exactly one <t:seconds:style> or <t:seconds> string into a frozen object with a new Date and style

A missing style becomes ShortDateTime. The Date has whole-second precision. Throws HelperError for malformed markup, nonpositive seconds or dates outside JavaScript's range. For text received from users, use tryParseTimestamp, which reports the same HelperError without throwing

parseTimestamp(value: string): TimestampMarkupparseTimestamp(
  value: string
): TimestampMarkup

Parameters

value
string

roleMention#

Create <@&id> text for a decimal role ID, such as <@&123>, and return it directly

Throws HelperError for an invalid ID. Role members are not notified merely because this text appears in a message, and allowedMentions must be set separately

roleMention(id: string): string

Parameters

id
string
Returns
string

timestamp#

Create <t:seconds:style> message text from a Date, which Fluxer displays in the reader's local time

The style defaults to ShortDateTime, and milliseconds are dropped. The whole Unix second must be from 1 through 8_640_000_000_000. Throws HelperError for an invalid Date, a time outside that range or an unsupported style. The input Date is not changed

timestamp(value: Date, style?: TimestampStyle): stringtimestamp(
  value: Date,
  style?: TimestampStyle
): string

Parameters

value
Date
style optional
TimestampStyle
Returns
string

tryParseCustomEmoji#

Read custom-emoji markup with the same rules as parseCustomEmoji, but report invalid text without throwing

The default API returns a Result holding the frozen name, ID and animated fields or HelperError. The native API returns an Effect that reads the text when run and fails with HelperError. Use it for text received from users or other untrusted sources

tryParseCustomEmoji(value: string): Result<
    CustomEmojiMarkup, HelperError
>tryParseCustomEmoji(
  value: string
): Result<
  CustomEmojiMarkup, HelperError
>

Parameters

value
string
Fails with

tryParseMention#

Read a mention with the same rules as parseMention, but report invalid text without throwing

The default API returns a Result holding the frozen { kind, id } object or HelperError. The native API returns an Effect that reads the text when run and fails with HelperError. Use it for text received from users or other untrusted sources

tryParseMention(value: string): Result<Mention, HelperError>tryParseMention(value: string): Result<
  Mention, HelperError
>

Parameters

value
string
Returns
Result<Mention, HelperError>
Fails with

tryParseTimestamp#

Read timestamp markup with the same rules as parseTimestamp, but report invalid text without throwing

The default API returns a Result holding the frozen date and style or HelperError. The native API returns an Effect that reads the text when run and fails with HelperError. Use it for text received from users or other untrusted sources

tryParseTimestamp(value: string): Result<
    TimestampMarkup, HelperError
>tryParseTimestamp(
  value: string
): Result<
  TimestampMarkup, HelperError
>

Parameters

value
string
Fails with

userMention#

Create <@id> text for a decimal user ID, such as <@123>, and return it directly

Throws HelperError when the ID is not a valid decimal-string snowflake. This does not look up the user, and allowedMentions must be set separately to request a notification

userMention(id: string): string

Parameters

id
string
Returns
string

LinkHelpers#

Methods of the links helper, which builds Fluxer channel, message and installation URLs

Each method returns the URL directly and throws HelperError for invalid input

type LinkHelpers = Readonly<{ … }>

channel#

Build a hosted community-channel or direct-message URL from { id, guildId } for a community channel or { id } for a private conversation

DirectMessageChannel inputs use Fluxer's /channels/@me/:channelId route. Throws HelperError for invalid decimal IDs. A URL does not prove the channel exists or the reader can open it

channel(target: ChannelLinkTarget): stringchannel(
  target: ChannelLinkTarget
): string

Parameters

Returns
string

installation#

Build a URL for Fluxer's bot-installation flow from an application ID, with the fixed bot scope and optional unsigned 64-bit permissions

For the hosted links export, the URL starts at Fluxer's API authorization route, which redirects to the web app's installation page wherever Fluxer currently serves it. Instance links open the instance web app's installation page directly. Throws HelperError for invalid IDs or options, and an alternate origin or scope is not accepted. This does not open the page, install the bot, authorize permissions or check whether the application exists

installation(
    applicationId: string,
    options?: InstallationLinkOptions
): stringinstallation(
  applicationId: string,
  options?: InstallationLinkOptions
): string

Parameters

applicationId
string
options optional
InstallationLinkOptions
Returns
string

message#

Build a hosted message URL in the supplied actual community-channel or direct-message context

Message and channel IDs must match, otherwise the call throws HelperError. Private versus community context is not inferred from the message alone, and access is not checked

message(
    message: MessageReference,
    channel: ChannelLinkTarget
): stringmessage(
  message: MessageReference,
  channel: ChannelLinkTarget
): string

Parameters

Returns
string

Mention#

The result of format.parseMention

Read kind to identify what was mentioned and id to get its decimal ID

type Mention =
    | { readonly id: string; readonly kind: "user" }
    | { readonly id: string; readonly kind: "role" }
    | { readonly id: string; readonly kind: "channel" }type Mention =
    | {
        readonly id: string
        readonly kind: "user"
      }
    | {
        readonly id: string
        readonly kind: "role"
      }
    | {
        readonly id: string
        readonly kind: "channel"
      }

MissingMessageBody#

The type of MessageBuilder.build before a body is selected

Calling it fails to compile with an error that names the missing argument selectContentEmbedAttachmentOrStickerBeforeBuild, which states the fix

type MissingMessageBody =
    (selectContentEmbedAttachmentOrStickerBeforeBuild: never)
        => nevertype MissingMessageBody =
    (
      selectContentEmbedAttachmentOrStickerBeforeBuild:
        never
    ) => never

RgbColor#

A three-item array of red, green and blue amounts, in that order

Each must be an integer from 0 through 255

type RgbColor = readonly [red: number, green: number, blue: number]type RgbColor =
    readonly [
      red: number,
      green: number,
      blue: number
    ]

SnowflakeHelpers#

Methods of the snowflakes helper, which reads and converts decimal Fluxer IDs without losing precision

type SnowflakeHelpers = Readonly<{ … }>type SnowflakeHelpers =
    Readonly<{ … }>

boundary#

Make the smallest ID for a Date's exact UTC millisecond, useful as a time-based pagination boundary

Throws HelperError for an invalid Date, a date before 2015-01-01 UTC or a result outside the ID range. This does not create a resource. Whether the boundary is included depends on the endpoint using it

boundary(value: Date): string

Parameters

value
Date
Returns
string

createdAt#

Return a new UTC Date for the creation time encoded in an ID

Throws HelperError for an invalid ID. This decodes the ID's high 41 timestamp bits relative to 2015-01-01 UTC, and does not fetch the resource or prove it is visible

createdAt(value: string): Date

Parameters

value
string
Returns
Date

isValid#

Return true for a decimal string from "0" through "9223372036854775807", with no extra leading zeroes

Returns false immediately for numbers, whitespace and invalid strings, without converting through Number or failing

isValid(value: unknown): value is stringisValid(
  value: unknown
): value is string

Parameters

value
unknown
Returns
value is string

parse#

Convert a valid decimal-string ID to bigint without losing precision

Throws HelperError for an invalid ID. For IDs received from users, use tryParse, which reports the same HelperError without throwing

parse(value: string): bigint

Parameters

value
string
Returns
bigint

shardFor#

Return the shard that receives a community's gateway events when the bot runs totalShards shards

Fluxer calls a community a guild, so the first argument is a guild ID. Fluxer routes each community with (guildId >> 22) % totalShards, and this helper applies the same formula. Use it to find which process owns a community when shards run in several processes. Throws HelperError for an invalid ID or a totalShards outside 1 through 16,384. It does not check whether the bot belongs to that community

shardFor(guildId: string, totalShards: number): numbershardFor(
  guildId: string,
  totalShards: number
): number

Parameters

guildId
string
totalShards
number
Returns
number

tryParse#

Convert a decimal-string ID with the same rules as parse, but report an invalid ID without throwing

The default API returns a Result holding the bigint or HelperError. The native API returns an Effect that reads the ID when run and fails with HelperError. Use it for IDs received from users or other untrusted sources

tryParse(value: string): Result<bigint, HelperError>tryParse(value: string): Result<
  bigint, HelperError
>

Parameters

value
string
Returns
Result<bigint, HelperError>
Fails with

TextHelpers#

Methods of the text helper, which splits and truncates long strings

type TextHelpers = Readonly<{ … }>

split#

Split text into a frozen array of pieces, each with string.length at most options.maxLength UTF-16 units

Prefer the last newline within a full piece, then the last whitespace, otherwise split a long word. Whitespace stays in the preceding piece, so joining with an empty separator reconstructs the input. Each lone surrogate, such as half of an emoji left by slice, first becomes U+FFFD (�) of the same length, because Fluxer refuses a lone surrogate. The pieces then join to content.toWellFormed(). To reject such text instead, check content.isWellFormed() first. Empty text gives []

split(content: string, options: TextSplitOptions): readonly string[]split(
  content: string,
  options: TextSplitOptions
): readonly string[]

No trimming, prefix or suffix insertion, Markdown repair, message-length lookup or remote request occurs. Every piece ends at a grapheme boundary of Intl.Segmenter, so a visible character stays whole: The two UTF-16 units of a single Unicode code point, a base character with its combining marks, a flag, a skin-tone emoji, a joined emoji and "\r\n" are never separated. A piece can therefore be shorter than maxLength. Only a single character longer than maxLength is cut, between code points. Throws HelperError for text that is not a string, invalid options, or a ceiling too small for a surrogate pair. Input and returned pieces are application-owned, and result size is proportional to the supplied text

Parameters

content
string
Returns
readonly string[]

truncate#

Shorten text to at most options.maxLength UTF-16 units, ending in options.suffix when anything was cut

Each lone surrogate, such as half of an emoji left by slice, first becomes U+FFFD (�) of the same length, because Fluxer refuses a lone surrogate. To reject such text instead, check content.isWellFormed() first. Text that then fits is returned as it is. Otherwise the text is cut so that the kept text and the suffix together fit, at a grapheme boundary of Intl.Segmenter, so only whole visible characters are kept: The two UTF-16 units of a single Unicode code point, a base character with its combining marks, a flag, a skin-tone emoji and a joined emoji are never separated, which can leave the result shorter than maxLength. When the first character does not fit in the room before the suffix, or no room is left, the suffix alone is returned. The suffix defaults to "…" (U+2026), and a suffix of "" cuts without marking it

truncate(content: string, options: TextTruncateOptions): stringtruncate(
  content: string,
  options: TextTruncateOptions
): string

No trimming, word boundary, Markdown repair, message-length lookup or remote request occurs. To cut at a word boundary instead, take the first piece of text.split with a limit that leaves room for the suffix, and trim its end. Throws HelperError for text that is not a string. Also throws HelperError for options that are not an object with only maxLength and suffix, a maxLength that is not a positive safe integer, or a suffix that is not a well-formed string of at most maxLength units

Parameters

content
string
Returns
string