TypeScript SDK reference
Every export of `@mnema-xyz/bot-sdk`, with its signature and documentation. Generated from bot-sdk-js v3.5.0 (88d52692e249).
/site/vendor/bot-sdk-js/src/builders/commands
From src//site/vendor/bot-sdk-js/src/builders/commands.ts.
validateCommand
function. Throws a ValidationError when a command breaks a documented limit.
function validateCommand(c: CommandInput): void
validateCommands
function. Throws when a bulk registration breaks a limit (at most 50 commands, unique names).
function validateCommands(list: CommandInput[]): void
/site/vendor/bot-sdk-js/src/builders/components
From src//site/vendor/bot-sdk-js/src/builders/components.ts.
actionRow
function. An action row: up to 5 buttons, or exactly one select (in a message), or exactly one text input (in a modal).
function actionRow(...components: (MessageRowComponent | MessageRowComponent[])[]): ActionRow<MessageRowComponent>;
button
function. A button that sends an interaction with its customId when clicked.
function button(o: ButtonOptions): ButtonComponent
ButtonOptions
interface
interface ButtonOptions {
customId: string;
label?: string;
emoji?: Emoji;
style?: 1 | 2 | 3 | 4;
disabled?: boolean;
}
channelSelect
function. A select menu of text, forum and announcement channels.
function channelSelect(o: SelectOptions): ChannelSelectComponent
linkButton
function. A button that opens a URL (style 5); clicks reach no bot.
function linkButton(o: LinkButtonOptions): ButtonComponent
LinkButtonOptions
interface
interface LinkButtonOptions {
url: string;
label?: string;
emoji?: Emoji;
disabled?: boolean;
}
roleSelect
function. A select menu of roles (not
function roleSelect(o: SelectOptions): RoleSelectComponent
SelectOptions
interface
interface SelectOptions {
customId: string;
placeholder?: string;
minValues?: number;
maxValues?: number;
disabled?: boolean;
}
stringSelect
function. A select menu of fixed options (1 to 25).
function stringSelect(o: SelectOptions & {
options: StringSelectOptionInput[];
}): StringSelectComponent
StringSelectOptionInput
interface
interface StringSelectOptionInput {
label: string;
value: string;
description?: string;
emoji?: Emoji;
default?: boolean;
}
userSelect
function. A select menu of members.
function userSelect(o: SelectOptions): UserSelectComponent
/site/vendor/bot-sdk-js/src/builders/modal
From src//site/vendor/bot-sdk-js/src/builders/modal.ts.
modal
function. A modal, the data of callback type 9 (see Interaction.showModal).
function modal(o: ModalOptions): ModalData
ModalOptions
interface
interface ModalOptions {
customId: string;
title: string;
components: (TextInputComponent | ActionRow<TextInputComponent>)[];
}
textInput
function. A text input of a modal.
function textInput(o: TextInputOptions): TextInputComponent
TextInputOptions
interface
interface TextInputOptions {
customId: string;
label: string;
style?: 1 | 2;
minLength?: number;
maxLength?: number;
required?: boolean;
value?: string;
placeholder?: string;
}
/site/vendor/bot-sdk-js/src/builders/validate
From src//site/vendor/bot-sdk-js/src/builders/validate.ts.
validateMessageComponents
function. The components of a message: up to 5 rows, 25 components, unique custom_ids.
function validateMessageComponents(rows: ActionRow<MessageRowComponent>[]): void
validateModal
function. A modal: a title of up to 45 characters and 1 to 5 rows of one text input each.
function validateModal(m: ModalData): void
ValidationError
class. A component, modal or command that breaks a documented limit.
class ValidationError {
override name = 'ValidationError';
}
/site/vendor/bot-sdk-js/src/client/client
From src//site/vendor/bot-sdk-js/src/client/client.ts.
Client
class
class Client {
readonly rest: RestClient;
readonly gateway: Gateway;
readonly commands: CommandManager;
/** The bot as READY showed it; undefined before the first READY. */
user: ReadyUser | undefined;
constructor(options: ClientOptions)
/** Checks the token (GET /users/@me) and connects the gateway; resolves with READY. */
async connect(): Promise<Ready>
/** Closes the gateway; no reconnect, no timer stays. */
close(): Promise<void>
/** Sets the bot's status and activity (gateway op 3, at most 5 per minute). */
setPresence(presence: PresenceData): void
}
ClientEvents
type
type ClientEvents = {
ready: [
ready: Ready
];
resumed: [
];
messageCreate: [
message: Message
];
messageUpdate: [
message: Message
];
messageDelete: [
event: MessageDeleteEvent
];
reactionsUpdate: [
event: ReactionsUpdateEvent
];
channelsUpdate: [
];
memberAdd: [
member: MemberAddEvent
];
interactionCreate: [
interaction: Interaction
];
raw: [
name: string,
data: unknown,
seq: number
];
error: [
error: Error
];
close: [
info: GatewayCloseInfo
];
debug: [
message: string
];
};
ClientOptions
interface
interface ClientOptions {
baseUrl: string;
token: string;
intents: number | readonly number[];
presence?: PresenceData;
logger?: Logger;
rest?: Omit<RestOptions, 'baseUrl' | 'token' | 'logger'>;
gateway?: Partial<Omit<GatewayOptions, 'token' | 'intents' | 'presence' | 'logger'>>;
}
gatewayUrlFor
function. The gateway address derived from the server's: https becomes wss.
function gatewayUrlFor(baseUrl: string): string
/site/vendor/bot-sdk-js/src/client/commands
From src//site/vendor/bot-sdk-js/src/client/commands.ts.
CommandManager
class
class CommandManager {
constructor(rest: RestClient)
/** Replaces all commands (PUT /commands); commands an admin disabled stay. */
set(commands: CommandInput[]): Promise<Command[]>
/** Adds a command, or updates the one with the same name (POST /commands). */
create(command: CommandInput): Promise<Command>
list(): Promise<Command[]>
delete(id: string): Promise<void>
}
/site/vendor/bot-sdk-js/src/client/interaction
From src//site/vendor/bot-sdk-js/src/client/interaction.ts.
EditData
type. What editReply and update take: a string is the content. No ephemeral or flags: the first response decides whether an answer is ephemeral.
type EditData = string | InteractionEditData;
Interaction
class
class Interaction {
readonly id: string;
readonly token: string;
readonly type: 2 | 3 | 5;
readonly channelId: string;
readonly applicationId: string;
/** The member who ran the command, clicked or submitted; the server sends it with every interaction. */
readonly user: InteractionUser;
/** The member who triggered the interaction, including channel permissions. */
readonly member: InteractionMember;
/** The message a component is on (also for a modal opened from a component). */
readonly message: InteractionMessage | undefined;
/** The command's name (type 2), else ''. */
readonly commandName: string;
/** The command's id (type 2). */
readonly commandId: string | undefined;
/** The command's options by name (type 2). */
readonly options: Map<string, string | number | boolean>;
/** The custom_id of the component or modal (types 3 and 5), else ''. */
readonly customId: string;
/** The component's type (type 3). */
readonly componentType: number | undefined;
/** The picked values of a select (type 3), else []. */
readonly values: string[];
/** What user, role and channel selects picked. */
readonly resolved: ResolvedData | undefined;
/** The text inputs of a modal submit by custom_id (type 5). */
readonly fields: Map<string, string>;
/** The payload as it arrived. */
readonly raw: InteractionPayload;
/** Whether the first answer (reply, defer, update, modal) was sent. */
replied = false;
/** Whether the first answer was a deferral (deferReply or deferUpdate). */
deferred = false;
constructor(payload: InteractionPayload, rest: RestClient)
isCommand(): boolean
isComponent(): boolean
isButton(): boolean
isSelect(): boolean
isModalSubmit(): boolean
/** Checks whether the member who triggered the interaction has a permission in the channel (or has Administrator). Returns false if permissions are absent (e.g. from an older server). */
hasPermission(permission: bigint | number): boolean
/** Posts the response message (callback 4); `ephemeral` shows it to the member only. */
async reply(data: ReplyData): Promise<void>
/** Acknowledges now (callback 5); the answer follows with editReply or followUp. */
async deferReply(options: {
ephemeral?: boolean;
} = {}): Promise<void>
/** Edits the original response, or posts it after deferReply; undefined for an ephemeral note. */
async editReply(data: EditData): Promise<Message | undefined>
deleteReply(): Promise<void>
/** A further message (up to 5 responses in total); undefined for an ephemeral one. */
followUp(data: ReplyData): Promise<Message | undefined>
/** Updates the message the component is on (callback 7); absent fields stay. */
async update(data: EditData): Promise<void>
/** Acknowledges a click without changing anything yet (callback 6). */
async deferUpdate(): Promise<void>
/** Opens a modal (callback 9); not allowed in answer to a modal submit. */
async showModal(modal: ModalData): Promise<void>
}
ReplyData
type. What reply and followUp take: a string is the content.
type ReplyData = string | (InteractionResponseData & {
ephemeral?: boolean;
});
/site/vendor/bot-sdk-js/src/constants
From src//site/vendor/bot-sdk-js/src/constants.ts.
ActivityType
const. Activity types of a presence update (streaming is not offered).
const ActivityType: { readonly Playing: 0; readonly Listening: 2; readonly Watching: 3; readonly Custom: 4; readonly Competing: 5;}
ActivityTypeValue
type
type ActivityTypeValue = (typeof ActivityType)[keyof typeof ActivityType];
API_BASE_PATH
const. The REST API's base path.
const API_BASE_PATH: "/api/bot/v1"
ButtonStyle
const
const ButtonStyle: { readonly Primary: 1; readonly Secondary: 2; readonly Success: 3; readonly Danger: 4; readonly Link: 5;}
ButtonStyleValue
type
type ButtonStyleValue = (typeof ButtonStyle)[keyof typeof ButtonStyle];
CallbackType
const
const CallbackType: { readonly ChannelMessageWithSource: 4; readonly DeferredChannelMessageWithSource: 5; readonly DeferredUpdateMessage: 6; readonly UpdateMessage: 7; readonly Modal: 9;}
CallbackTypeValue
type
type CallbackTypeValue = (typeof CallbackType)[keyof typeof CallbackType];
ComponentType
const
const ComponentType: { readonly ActionRow: 1; readonly Button: 2; readonly StringSelect: 3; readonly TextInput: 4; readonly UserSelect: 5; readonly RoleSelect: 6; readonly ChannelSelect: 8;}
ComponentTypeValue
type
type ComponentTypeValue = (typeof ComponentType)[keyof typeof ComponentType];
GatewayCloseCode
const. Close codes the bot gateway uses.
const GatewayCloseCode: { readonly SessionTakenOver: 4000; readonly UnknownOpcode: 4001; readonly DecodeError: 4002; readonly NotAuthenticated: 4003; readonly AuthenticationFailed: 4004; readonly AlreadyAuthenticated: 4005; readonly InvalidSeq: 4007; readonly RateLimited: 4008; readonly SessionTimedOut: 4009; readonly InvalidIntents: 4013; readonly DisallowedIntents: 4014;}
GatewayOp
const. Gateway opcodes.
const GatewayOp: { readonly Dispatch: 0; readonly Heartbeat: 1; readonly Identify: 2; readonly PresenceUpdate: 3; readonly Resume: 6; readonly Reconnect: 7; readonly InvalidSession: 9; readonly Hello: 10; readonly HeartbeatAck: 11;}
hasPermission
function. Checks whether a member permissions bitfield (decimal string, bigint or number) includes a permission. Returns true if the member has the specific permission or Administrator (which grants all permissions).
function hasPermission(permissions: string | bigint | number | undefined | null, permission: bigint | number): boolean
IntentBit
type
type IntentBit = (typeof Intents)[keyof typeof Intents];
IntentName
type. Intent names as a manifest lists them.
type IntentName = 'GUILDS' | 'GUILD_MEMBERS' | 'GUILD_MESSAGES' | 'GUILD_MESSAGE_REACTIONS';
Intents
const. Gateway intents: bits of IDENTIFY's intents.
const Intents: { readonly Guilds: 1; readonly GuildMembers: 2; readonly GuildMessages: 512; readonly GuildMessageReactions: 1024;}
InteractionType
const
const InteractionType: { readonly ApplicationCommand: 2; readonly MessageComponent: 3; readonly ModalSubmit: 5;}
InteractionTypeValue
type
type InteractionTypeValue = (typeof InteractionType)[keyof typeof InteractionType];
MessageFlags
const. Message flags.
const MessageFlags: { readonly Ephemeral: 64;}
OptionType
const. Slash command option types.
const OptionType: { readonly String: 3; readonly Integer: 4; readonly Boolean: 5; readonly User: 6; readonly Channel: 7;}
OptionTypeValue
type
type OptionTypeValue = (typeof OptionType)[keyof typeof OptionType];
PermissionBit
type
type PermissionBit = (typeof Permissions)[keyof typeof Permissions];
Permissions
const. Mnema Talk's permission bits.
Mnema's permission bits have their own values: bit constants from other chat libraries do not match them. Use these, compute bits from Mnema's catalogue or pass an array of permission keys.
const Permissions: { readonly Administrator: 1n; readonly ViewChannel: 2n; readonly SendMessages: 4n; readonly AttachFiles: 8n; readonly AddReactions: 16n; readonly ManageMessages: 32n; readonly MentionEveryone: 64n; readonly Connect: 128n; readonly Speak: 256n; readonly Video: 512n; readonly DisconnectMembers: 1024n; readonly ManageChannels: 2048n; readonly ManageRoles: 4096n; readonly CreateInvites: 8192n; readonly ManageWebhooks: 16384n; readonly ManageMembers: 32768n; readonly ManageBots: 65536n; readonly ViewAuditLog: 131072n; readonly TimeoutMembers: 262144n; readonly BanMembers: 524288n; readonly ManageEmoji: 1048576n; readonly ManageReports: 2097152n; readonly SendDirectMessages: 4194304n; readonly KickMembers: 8388608n; readonly ManageStage: 16777216n; readonly ManageEvents: 33554432n; readonly BypassNewMemberLimits: 67108864n; readonly EditWiki: 134217728n; readonly ManageWiki: 268435456n; readonly ViewWiki: 536870912n; readonly CreateMemberInvites: 1073741824n;}
TextInputStyle
const
const TextInputStyle: { readonly Short: 1; readonly Paragraph: 2;}
TextInputStyleValue
type
type TextInputStyleValue = (typeof TextInputStyle)[keyof typeof TextInputStyle];
/site/vendor/bot-sdk-js/src/emitter
From src//site/vendor/bot-sdk-js/src/emitter.ts.
Emitter
class
class Emitter {
on<K extends keyof E>(event: K, listener: (...args: E[K]) => unknown): this
once<K extends keyof E>(event: K, listener: (...args: E[K]) => unknown): this
off<K extends keyof E>(event: K, listener: (...args: E[K]) => unknown): this
listenerCount<K extends keyof E>(event: K): number
}
/site/vendor/bot-sdk-js/src/gateway/gateway
From src//site/vendor/bot-sdk-js/src/gateway/gateway.ts.
Gateway
class
class Gateway {
constructor(options: GatewayOptions)
/** The session id of READY, while there is one. */
get session(): {
id: string;
seq: number | null;
} | undefined
/** Connects; resolves with the first READY, rejects on a fatal close or close(). */
connect(): Promise<Ready>
/** Closes the connection for good: no reconnect, no timer stays. */
close(code = 1000): Promise<void>
/** Sets the bot's status and activity (op 3); kept for the IDENTIFY of later connections. */
setPresence(presence: PresenceData): void
/** Sends a raw frame, within the frame size and rate limits. */
send(op: number, d: unknown): void
}
GatewayCloseInfo
interface
interface GatewayCloseInfo {
code: number;
reason: string;
reconnect: boolean;
}
GatewayEvents
type
type GatewayEvents = {
ready: [
ready: Ready
];
resumed: [
];
dispatch: [
name: string,
data: unknown,
seq: number
];
close: [
info: GatewayCloseInfo
];
error: [
error: Error
];
debug: [
message: string
];
};
GatewayOptions
interface
interface GatewayOptions {
token: string;
intents: number | readonly number[];
url: string | (() => Promise<string>);
presence?: PresenceData;
properties?: Record<string, string>;
logger?: Logger;
webSocketFactory?: WebSocketFactory;
reconnect?: BackoffOptions;
resumeWindowMs?: number;
random?: () => number;
}
/site/vendor/bot-sdk-js/src/gateway/outbox
From src//site/vendor/bot-sdk-js/src/gateway/outbox.ts.
FrameTooLargeError
class
class FrameTooLargeError {
override name = 'FrameTooLargeError';
}
MAX_FRAME_BYTES
const
const MAX_FRAME_BYTES: 4096
/site/vendor/bot-sdk-js/src/gateway/policy
From src//site/vendor/bot-sdk-js/src/gateway/policy.ts.
BackoffOptions
interface
interface BackoffOptions {
minDelayMs?: number;
maxDelayMs?: number;
rateLimitedDelayMs?: number;
}
closeAction
function
function closeAction(code: number): CloseAction
CloseAction
type. - fatal: stop and report (bad token, intents not allowed).
identify: reconnect with a new session.resume: reconnect and resume the session.rateLimited: resume after a longer pause.
type CloseAction = 'fatal' | 'identify' | 'resume' | 'rateLimited';
GatewayError
class. A connection the gateway closed with a fatal code.
class GatewayError {
override name = 'GatewayError';
readonly code: number;
readonly reason: string;
constructor(code: number, reason: string)
}
sanitizeResumeUrl
function. Ensures resume_gateway_url matches the origin and host of the base gateway URL. Prevents SSRF or redirection to unintended endpoints.
function sanitizeResumeUrl(resumeUrl: string | undefined, baseUrl: string): string
/site/vendor/bot-sdk-js/src/gateway/socket
From src//site/vendor/bot-sdk-js/src/gateway/socket.ts.
SocketCloseEvent
interface
interface SocketCloseEvent {
code: number;
reason: string;
}
WebSocketFactory
type
type WebSocketFactory = (url: string, headers: Record<string, string>) => WebSocketLike;
WebSocketLike
interface. What the gateway needs of a WebSocket (the standard WebSocket fits).
interface WebSocketLike {
readonly readyState: number;
send(data: string): void;
close(code?: number, reason?: string): void;
addEventListener(type: 'open', listener: () => void): void;
addEventListener(type: 'message', listener: (ev: {
data: unknown;
}) => void): void;
addEventListener(type: 'close', listener: (ev: SocketCloseEvent) => void): void;
addEventListener(type: 'error', listener: (ev: unknown) => void): void;
}
/site/vendor/bot-sdk-js/src/manifest
From src//site/vendor/bot-sdk-js/src/manifest.ts.
addBotLink
function. The link that opens the server's confirm screen for this manifest:
${serverUrl}/admin/bots/add#manifest=<base64url JSON>. The manifest is in
the fragment, which the browser never sends to the server.
function addBotLink(serverUrl: string, manifest: Manifest): string
decodeManifest
function. The JSON of an encoded manifest (the inverse of encodeManifest).
function decodeManifest(encoded: string): Manifest
encodeManifest
function. The manifest as base64url of its JSON (UTF-8), the fragment of the add link.
function encodeManifest(manifest: Manifest): string
Manifest
interface
interface Manifest {
manifest_version: 1;
name: string;
description?: string;
homepage?: string;
avatar?: string;
intents?: IntentName[];
permissions?: ManifestPermission[];
commands?: CommandInput[];
}
ManifestPermission
type
type ManifestPermission = 'view_channel' | 'send_messages' | 'attach_files' | 'add_reactions' | 'manage_messages' | 'mention_everyone';
/site/vendor/bot-sdk-js/src/rest/client
From src//site/vendor/bot-sdk-js/src/rest/client.ts.
DownloadAttachmentOptions
type
type DownloadAttachmentOptions = DownloadOptions;
RestClient
class
class RestClient {
constructor(options: RestOptions)
/** The server address without a trailing slash. */
get baseUrl(): string
/** Any route under /api/bot/v1, with the same buckets and retries. */
request<T = unknown>(method: string, path: string, options?: RequestOptions): Promise<T>
getMe(): Promise<BotSelf>
getGateway(): Promise<GatewayInfo>
listChannels(): Promise<ChannelHierarchy>
listMessages(channelId: string, query: ListMessagesQuery = {}): Promise<Message[]>
getMessage(channelId: string, messageId: string): Promise<Message>
/** Posts a message; a string is the content. */
createMessage(channelId: string, data: CreateMessageData | string): Promise<Message>
/** Edits an own message: absent fields stay, `components: []` removes them. */
editMessage(channelId: string, messageId: string, data: EditMessageData | string): Promise<Message>
deleteMessage(channelId: string, messageId: string): Promise<void>
/** Reacts with a Unicode emoji or a custom one as `<:name:id>`. */
addReaction(channelId: string, messageId: string, emoji: string): Promise<void>
removeReaction(channelId: string, messageId: string, emoji: string): Promise<void>
/** Uploads a file (multipart `file`), with an optional caption. */
uploadFile(channelId: string, data: UploadFileData): Promise<Message>
/** Streams a message attachment by its media id without following redirects. Throws NotFoundError if missing or not accessible to the bot. Throws MaxBytesExceededError if maxBytes is exceeded. */
downloadAttachment(id: string, options?: DownloadAttachmentOptions): Promise<DownloadedAttachment>
/** Needs the GUILD_MEMBERS intent allowed. */
listMembers(): Promise<Member[]>
getMember(userId: string): Promise<Member>
listCommands(): Promise<Command[]>
/** Replaces all commands (bulk overwrite). */
setCommands(commands: CommandInput[]): Promise<Command[]>
/** Adds a command or updates the one with the same name. */
createCommand(command: CommandInput): Promise<Command>
deleteCommand(commandId: string): Promise<void>
/** The first answer to an interaction (callback types 4, 5, 6, 7, 9). */
createInteractionResponse(id: string, token: string, callback: InteractionCallback): Promise<void>
/** A further message; answers undefined for an ephemeral one. */
createFollowup(id: string, token: string, data: InteractionResponseData): Promise<Message | undefined>
/** Edits (or, after callback 5, posts) the original response; undefined for an ephemeral note. */
editOriginalResponse(id: string, token: string, data: InteractionEditData): Promise<Message | undefined>
deleteOriginalResponse(id: string, token: string): Promise<void>
}
/site/vendor/bot-sdk-js/src/rest/core
From src//site/vendor/bot-sdk-js/src/rest/core.ts.
DownloadedAttachment
interface
interface DownloadedAttachment {
contentType: string;
size?: number;
filename?: string;
stream: ReadableStream<Uint8Array>;
}
DownloadOptions
interface
interface DownloadOptions {
maxBytes?: number;
signal?: AbortSignal;
timeoutMs?: number;
}
RateLimitInfo
interface
interface RateLimitInfo {
method: string;
path: string;
bucket: string;
retryAfter: number;
global: boolean;
scope: string | undefined;
attempt: number;
willRetry: boolean;
}
RequestOptions
interface
interface RequestOptions {
query?: Record<string, string | number | boolean | undefined>;
body?: unknown;
form?: FormData;
signal?: AbortSignal;
}
RestOptions
interface
interface RestOptions {
baseUrl: string;
token: string;
timeoutMs?: number;
maxRetries?: number;
localRateLimits?: boolean;
onRateLimit?: (info: RateLimitInfo) => void;
logger?: Logger;
fetch?: typeof fetch;
userAgent?: string;
}
/site/vendor/bot-sdk-js/src/rest/error
From src//site/vendor/bot-sdk-js/src/rest/error.ts.
MaxBytesExceededError
class. Thrown when an attachment exceeds the configured maxBytes limit, either indicated by the Content-Length header or while streaming chunks.
class MaxBytesExceededError {
override name = 'MaxBytesExceededError';
readonly maxBytes: number;
readonly bytes?: number;
constructor(maxBytes: number, bytes?: number)
}
NotFoundError
class. A 404 answer of the REST API (e.g. unknown or inaccessible attachment, message, channel).
class NotFoundError {
override name = 'NotFoundError';
}
RequestFailedError
class. Thrown when a request got no answer (the connection failed, for example).
The message names the method and the route with an interaction or webhook
token replaced by :token, and the underlying error's message with the
token replaced likewise; cause is set only for a route without a token.
Aborts and timeouts are thrown as they are (AbortError, TimeoutError).
class RequestFailedError {
override name = 'RequestFailedError';
readonly method: string;
readonly path: string;
constructor(init: {
method: string;
path: string;
message: string;
cause?: unknown;
})
}
ResponseTooLargeError
class. Thrown when a JSON or error answer of the REST API is larger than the client reads (16 MiB).
class ResponseTooLargeError {
override name = 'ResponseTooLargeError';
readonly maxBytes: number;
/** The HTTP status of the answer. */
readonly status: number;
constructor(maxBytes: number, status: number)
}
RestError
class. An error answer of the REST API, in the shape {message, code}:
message is the server's message, status, method and path say where
(an interaction or webhook token in path is replaced by :token).
class RestError {
override name = 'RestError';
/** HTTP status. */
readonly status: number;
/** The JSON error code: 10003 unknown channel, 10008 unknown message, 50013 missing permissions, 50035 invalid form body, 0 plain HTTP errors. */
readonly code: number;
/** The parsed body (or the raw text when it was not JSON). */
readonly body: unknown;
readonly method: string;
readonly path: string;
/** Seconds to wait, on a 429 that ran out of retries. */
readonly retryAfter: number | undefined;
/** Whether a 429 hit the bot's overall limit. */
readonly global: boolean | undefined;
constructor(init: {
status: number;
method: string;
path: string;
body: unknown;
retryAfter?: number;
global?: boolean;
})
}
/site/vendor/bot-sdk-js/src/types/commands
From src//site/vendor/bot-sdk-js/src/types/commands.ts.
Command
interface. A registered command (GET /commands).
interface Command {
id: string;
bot_id: string;
name: string;
description: string;
options: CommandOption[];
disabled: boolean;
created_at: string;
default_member_permissions?: string | null;
}
CommandInput
interface. What a bot registers (PUT and POST /commands).
interface CommandInput {
name: string;
description: string;
options?: CommandOption[];
default_member_permissions?: DefaultMemberPermissionsInput;
}
CommandOption
interface
interface CommandOption {
name: string;
description: string;
type: OptionTypeValue;
required?: boolean;
choices?: string[];
}
DefaultMemberPermissionsInput
type
type DefaultMemberPermissionsInput = string | bigint | number | PermissionKey[] | string[] | null;
InteractionCallback
type
type InteractionCallback = {
type: 4;
data: InteractionResponseData;
} | {
type: 5;
data?: {
flags?: number;
};
} | {
type: 6;
} | {
type: 7;
data: InteractionEditData;
} | {
type: 9;
data: ModalData;
};
InteractionEditData
interface. The data of callback 7 and the body of an
interface InteractionEditData {
content?: string;
embeds?: Embed[];
components?: MessageComponents;
allowed_mentions?: AllowedMentions;
}
InteractionResponseData
interface. The data of callback 4 and the body of a follow-up: a message to post.
interface InteractionResponseData {
content?: string;
embeds?: Embed[];
components?: MessageComponents;
allowed_mentions?: AllowedMentions;
flags?: number;
}
PermissionKey
type
type PermissionKey = 'administrator' | 'view_channel' | 'send_messages' | 'attach_files' | 'add_reactions' | 'manage_messages' | 'mention_everyone' | 'connect' | 'speak' | 'video' | 'disconnect_members' | 'manage_channels' | 'manage_roles' | 'create_invites' | 'manage_webhooks' | 'manage_members' | 'manage_bots' | 'view_audit_log' | 'timeout_members' | 'ban_members' | 'manage_emoji' | 'manage_reports' | 'send_direct_messages' | 'kick_members' | 'manage_stage' | 'manage_events' | 'bypass_new_member_limits' | 'edit_wiki' | 'manage_wiki' | 'view_wiki' | 'create_member_invites';
/site/vendor/bot-sdk-js/src/types/components
From src//site/vendor/bot-sdk-js/src/types/components.ts.
ActionRow
interface
interface ActionRow<C = MessageRowComponent> {
type: 1;
components: C[];
}
ButtonComponent
interface
interface ButtonComponent {
type: 2;
style: 1 | 2 | 3 | 4 | 5;
label?: string;
emoji?: ComponentEmoji;
custom_id?: string;
url?: string;
disabled?: boolean;
}
ChannelSelectComponent
interface
interface ChannelSelectComponent extends SelectBase {
type: 8;
}
Component
type. Any component as it can appear on the wire.
type Component = ActionRow<MessageRowComponent | TextInputComponent> | MessageRowComponent | TextInputComponent;
ComponentEmoji
interface
interface ComponentEmoji {
name: string;
}
MessageComponents
type. The rows of a message: up to 5.
type MessageComponents = ActionRow<MessageRowComponent>[];
MessageRowComponent
type. A component inside an action row of a message.
type MessageRowComponent = ButtonComponent | SelectComponent;
ModalData
interface
interface ModalData {
custom_id: string;
title: string;
components: ActionRow<TextInputComponent>[];
}
RoleSelectComponent
interface
interface RoleSelectComponent extends SelectBase {
type: 6;
}
SelectComponent
type
type SelectComponent = StringSelectComponent | UserSelectComponent | RoleSelectComponent | ChannelSelectComponent;
SelectOption
interface
interface SelectOption {
label: string;
value: string;
description?: string;
emoji?: ComponentEmoji;
default?: boolean;
}
StringSelectComponent
interface
interface StringSelectComponent extends SelectBase {
type: 3;
options: SelectOption[];
}
SubmittedTextInput
interface. A submitted text input inside a modal submit interaction.
interface SubmittedTextInput {
type: 4;
custom_id: string;
value: string;
}
TextInputComponent
interface
interface TextInputComponent {
type: 4;
custom_id: string;
label?: string;
style?: 1 | 2;
min_length?: number;
max_length?: number;
required?: boolean;
value?: string;
placeholder?: string;
}
UserSelectComponent
interface
interface UserSelectComponent extends SelectBase {
type: 5;
}
/site/vendor/bot-sdk-js/src/types/gateway
From src//site/vendor/bot-sdk-js/src/types/gateway.ts.
Activity
interface
interface Activity {
name: string;
type: ActivityTypeValue;
state?: string;
}
CommandOptionValue
interface
interface CommandOptionValue {
name: string;
type: number;
value: string | number | boolean;
}
GatewayFrame
interface
interface GatewayFrame {
op: number;
d?: unknown;
s?: number | null;
t?: string | null;
}
InteractionData
interface
interface InteractionData {
id?: string;
name?: string;
options?: CommandOptionValue[];
custom_id?: string;
component_type?: number;
values?: string[];
resolved?: ResolvedData;
components?: {
type: 1;
components: SubmittedTextInput[];
}[];
}
InteractionMember
interface
interface InteractionMember {
user: InteractionUser;
permissions?: string;
}
InteractionMessage
type. The message a component is on, as INTERACTION_CREATE carries it.
type InteractionMessage = Partial<Message> & {
id: string;
content?: string;
components?: MessageComponents;
embeds?: Embed[];
flags?: number;
};
InteractionPayload
interface. The d of an INTERACTION_CREATE dispatch.
interface InteractionPayload {
id: string;
token: string;
type: 2 | 3 | 5;
channel_id: string;
application_id: string;
data: InteractionData;
member: InteractionMember;
message?: InteractionMessage;
}
InteractionUser
interface
interface InteractionUser {
id: string;
username: string;
display_name: string;
avatar_url?: string;
}
MemberAddEvent
interface
interface MemberAddEvent {
id: string;
username: string;
display_name: string;
avatar_url?: string;
}
MessageDeleteEvent
interface
interface MessageDeleteEvent {
id: string;
channel_id: string;
parent_id?: string | null;
}
PresenceData
interface
interface PresenceData {
status: PresenceStatus;
activity?: Activity | null;
}
PresenceStatus
type
type PresenceStatus = 'online' | 'idle' | 'dnd' | 'invisible';
ReactionsUpdateEvent
interface
interface ReactionsUpdateEvent {
message_id: string;
channel_id: string;
reactions: ReactionSummary[];
}
Ready
interface
interface Ready {
v: number;
user: ReadyUser;
session_id: string;
intents: number;
resume_gateway_url: string;
heartbeat_interval: number;
}
ReadyUser
interface
interface ReadyUser {
id: string;
bot_id: string;
username: string;
handle?: string;
bot: true;
avatar_url?: string;
}
ResolvedData
interface
interface ResolvedData {
users?: Record<string, InteractionUser>;
roles?: Record<string, {
id: string;
name: string;
color: number;
}>;
channels?: Record<string, {
id: string;
name: string;
type: string;
}>;
}
/site/vendor/bot-sdk-js/src/types/messages
From src//site/vendor/bot-sdk-js/src/types/messages.ts.
AllowedMentions
interface
interface AllowedMentions {
parse?: ('users' | 'everyone' | 'roles')[];
users?: string[];
roles?: string[];
}
Attachment
interface
interface Attachment {
id: string;
url: string;
mime_type: string;
original_filename: string;
size_bytes: number;
is_deleted: boolean;
filename?: string;
content_type?: string;
size?: number;
}
BotSelf
interface. GET /users/@me
interface BotSelf {
id: string;
bot_id: string;
username: string;
handle?: string;
bot: true;
avatar_url?: string;
allowed_intents: number;
}
Category
interface
interface Category {
id: string;
name: string;
sort_order: number;
created_at: string;
channels: Channel[];
}
Channel
interface
interface Channel {
id: string;
name: string;
type: ChannelType;
category_id: string | null;
created_at: string;
number: number;
slug?: string;
topic: string;
sort_order: number;
slow_mode_seconds: number;
user_limit: number;
auto_delete_days?: number;
previous_slugs?: string[];
is_lobby?: boolean;
is_stage?: boolean;
is_temp?: boolean;
leader_id?: string;
}
ChannelHierarchy
interface. GET /channels: the channels the bot can view, with their categories.
interface ChannelHierarchy {
categories: Category[];
uncategorized: Channel[];
}
ChannelType
type
type ChannelType = 'text' | 'voice' | 'forum' | (string & {});
CreateMessageData
interface. Body of POST /channels/{id}/messages.
interface CreateMessageData {
content?: string;
embeds?: Embed[];
components?: MessageComponents;
allowed_mentions?: AllowedMentions;
message_reference?: MessageReference;
parent_id?: string;
lifetime_seconds?: number;
}
EditMessageData
interface. Body of PATCH /channels/{id}/messages/{id}: absent fields stay.
interface EditMessageData {
content?: string;
components?: MessageComponents;
allowed_mentions?: AllowedMentions;
}
Embed
interface
interface Embed {
title?: string;
description?: string;
url?: string;
color?: number;
timestamp?: string;
author?: EmbedAuthor;
footer?: EmbedFooter;
image?: EmbedMedia;
thumbnail?: EmbedMedia;
fields?: EmbedField[];
}
EmbedAuthor
interface
interface EmbedAuthor {
name: string;
url?: string;
}
EmbedField
interface
interface EmbedField {
name: string;
value: string;
inline?: boolean;
}
EmbedFooter
interface
interface EmbedFooter {
text: string;
}
EmbedMedia
interface
interface EmbedMedia {
url: string;
}
GatewayInfo
interface. GET /gateway
interface GatewayInfo {
url: string;
heartbeat_interval: number;
max_connections: number;
}
ListMessagesQuery
interface
interface ListMessagesQuery {
limit?: number;
before?: string;
after?: string;
around?: string;
}
Member
interface
interface Member {
id: string;
username: string;
display_name: string;
avatar_url?: string;
bot?: boolean;
}
Message
interface
interface Message {
id: string;
channel_id: string;
user_id: string;
username: string;
display_name: string;
avatar_url?: string;
content: string;
created_at: string;
updated_at: string;
number: number;
is_edited: boolean;
is_pinned: boolean;
is_bot?: boolean;
is_webhook?: boolean;
is_locked?: boolean;
is_resolved?: boolean;
attachments: Attachment[];
embeds?: Embed[];
components?: MessageComponents;
reactions: ReactionSummary[];
mentions: string[];
direct_mentions?: string[];
mention_roles?: string[];
nonce?: string;
parent_id?: string;
reply_count: number;
reply_to_id?: string;
reply_to?: ReplyPreview;
forward?: {
forwarded: boolean;
};
poll?: Poll;
pinned_at?: string;
pinned_by?: UserRef;
last_activity_at?: string;
title?: string;
tags?: unknown[];
flags?: number;
expires_at?: string;
}
MessageReference
interface
interface MessageReference {
message_id: string;
}
Poll
interface
interface Poll {
options: PollOption[];
multiple: boolean;
anonymous: boolean;
closes_at: string;
closed: boolean;
total_voters: number;
}
PollOption
interface
interface PollOption {
id: string;
label: string;
votes: number;
voters?: string[];
}
ReactionSummary
interface
interface ReactionSummary {
emoji: string;
count: number;
users: string[];
}
ReplyPreview
interface
interface ReplyPreview {
id: string;
deleted: boolean;
user_id?: string;
username?: string;
display_name?: string;
avatar_url?: string;
content?: string;
has_attachments?: boolean;
is_bot?: boolean;
is_webhook?: boolean;
}
Snowflake
type. Ids are UUIDs.
type Snowflake = string;
UploadFileData
interface
interface UploadFileData {
file: Blob | Uint8Array;
name: string;
contentType?: string;
content?: string;
allowed_mentions?: AllowedMentions;
parent_id?: string;
reply_to_id?: string;
}
UserRef
interface
interface UserRef {
id: string;
username: string;
display_name: string;
avatar_url?: string;
}
/site/vendor/bot-sdk-js/src/util
From src//site/vendor/bot-sdk-js/src/util.ts.
Logger
interface
interface Logger {
debug?(message: string, ...args: unknown[]): void;
info?(message: string, ...args: unknown[]): void;
warn?(message: string, ...args: unknown[]): void;
error?(message: string, ...args: unknown[]): void;
}
/site/vendor/bot-sdk-js/src/version
From src//site/vendor/bot-sdk-js/src/version.ts.
VERSION
const. The SDK's version, the same as package.json's (a test checks it). A release bumps both; the publish workflow checks that the tag names this version.
const VERSION: "3.5.0"