Options
All
  • Public
  • Public/Protected
  • All
Menu

Gatekeeper API

Index

Type aliases

ActionRowChild

A valid child of actionRowComponent

ActionRowComponent

ActionRowComponent: { children: ActionRowChild[]; type: "actionRow" }

Returned from actionRowComponent

Type declaration

ButtonComponent

ButtonComponent: ButtonComponentOptions & { customId: string; type: "button" }

Returned from buttonComponent

ButtonComponentOptions

ButtonComponentOptions: { disabled?: boolean; emoji?: EmojiResolvable; label: string; onClick: any; style: Exclude<MessageButtonStyle, "LINK"> }

Options for buttonComponent

Type declaration

ButtonInteractionContext

ButtonInteractionContext: InteractionContext & { message: Message }

The context object received by button onClick handlers. See buttonComponent

CommandInfo

CommandInfo: { name: string }

Basic information about the commands currently added

Type declaration

  • name: string

    The name of the command

ConsoleLoggerLevel

ConsoleLoggerLevel: "info" | "success" | "error" | "warn"

EmbedComponent

EmbedComponent: { embed: MessageEmbed | MessageEmbedOptions; type: "embed" }

Returned from embedComponent

Type declaration

  • embed: MessageEmbed | MessageEmbedOptions
  • type: "embed"

GatekeeperConfig

GatekeeperConfig: { client: Client; commandFolder?: string; logging?: boolean | ConsoleLoggerLevel[]; name?: string; onError?: any; scope?: "guild" | "global" | "both" }

Options for creating a gatekeeper instance

Type declaration

  • client: Client

    A Discord.JS client

  • Optional commandFolder?: string

    An absolute path to a folder with command files. Each file should export default a function to accept a gatekeeper instance and add commands to it.

    // main.ts
    Gatekeeper.create({
    commandFolder: join(__dirname, "commands"),
    })
    // commands/ping.ts
    export default function addCommands(gatekeeper) {
    gatekeeper.addCommand({
    name: "ping",
    description: "Pong!",
    run: (ctx) => ctx.reply(() => "Pong!"),
    })
    }
  • Optional logging?: boolean | ConsoleLoggerLevel[]

    Show colorful debug logs in the console

  • Optional name?: string

    The name of the bot, used for logger messages

  • onError?:function
    • onError(error: Error): void
    • Called when any error occurs. You can use this to log your own errors, send them to an error reporting service, etc.

      Parameters

      • error: Error

      Returns void

  • Optional scope?: "guild" | "global" | "both"

    Where commands should be registered.

    guild - Register commands in all guilds (servers) that the bot joins, which appear immediately. This is the default, and recommended for testing, or if your bot is just in a few guilds.

    global - Register commands globally, which can take a few minutes or an hour to show up. Since bots have a global command limit, this is good for when your bot grows beyond just a few servers.

    both - Register commands in both guilds and globally.

    See the discord docs for more info: https://discord.com/developers/docs/interactions/application-commands#registering-a-command

InteractionContext

InteractionContext: { channel: TextBasedChannels | undefined; defer: any; ephemeralDefer: any; ephemeralReply: any; guild: Guild | undefined; member: GuildMember | undefined; reply: any; user: User }

Base type for all context objects

Type declaration

  • Readonly channel: TextBasedChannels | undefined

    The channel that this interaction took place in.

  • defer:function
    • defer(): void
  • ephemeralDefer:function
    • ephemeralDefer(): void
    • Same as {@link InteractionContext.defer defer}, but shows the loading message only to the interacting user.

      Returns void

  • ephemeralReply:function
    • Like {@link InteractionContext.reply reply}, but only shows the message to the interacting user.

      This does not return a reply handle; ephemeral replies can't be updated or deleted manually

      Parameters

      Returns void

  • Readonly guild: Guild | undefined

    The guild that this interaction took place in.

  • Readonly member: GuildMember | undefined

    The guild member for the user that triggered this interaction

  • reply:function
  • Readonly user: User

    The user that triggered this interaction. For buttons, this is the user that clicked the button, and so on

LinkComponent

LinkComponent: LinkComponentOptions & { type: "link" }

Returned from linkComponent

LinkComponentOptions

LinkComponentOptions: { emoji?: EmojiResolvable; label: string; url: string }

Options for the link component

see

linkComponent

Type declaration

MessageCommandConfig

MessageCommandConfig: { aliases?: string[]; name: string; run: any }

Options for creating a message command. Shows when right-clicking a message.

see

Gatekeeper.addMessageCommand

Type declaration

MessageCommandInteractionContext

MessageCommandInteractionContext: InteractionContext & { targetMessage: Message }

The context object received when running a message command

RenderReplyFn

RenderReplyFn: () => RenderResult

Type declaration

RenderResult

RenderResult: ReplyComponent | string | number | boolean | undefined | null | RenderResult[]

Anything that can be rendered in a reply.

  • Embed components, action row components, and text components are accepted as-is
  • Button and select menu components are automatically placed in action rows, respecting discord's restrictions
  • Strings and numbers become text components. Empty strings can be used to add empty lines in the message. \n will also add a new line.
  • Nested arrays are flattened
  • Everything else (booleans, undefined, null) is ignored

ReplyComponent

Any reply component object

ReplyHandle

ReplyHandle: { delete: any; get message(): undefined | Message<boolean>; refresh: any }

Returned from {@link InteractionContext.reply}, for arbitrarily doing stuff with a reply message

Type declaration

  • delete:function
    • delete(): void
  • get message(): undefined | Message<boolean>

    The discord message associated with this reply

  • refresh:function
    • refresh(): void
    • Refresh the reply message.

      Gatekeeper will call this automatically on a component interaction, but you can do so yourself when you want to update the message outside of a component interaction

      Returns void

SelectMenuComponent

SelectMenuComponent: Omit<SelectMenuComponentOptions, "selected"> & { customId: string; type: "selectMenu" }

Returned from selectMenuComponent

SelectMenuComponentOptions

SelectMenuComponentOptions: { maxValues?: number; minValues?: number; onSelect: any; options: MessageSelectOptionData[]; placeholder?: string; selected?: Iterable<string> | string }

Options passed to selectMenuComponent

Type declaration

  • Optional maxValues?: number

    The maximum number of options that can be selected. Passing this option will enable multi-select, and can't be greater than the number of options.

  • Optional minValues?: number

    The minimum number of options that can be selected. Passing this option will enable multi-select, and can't be 0.

  • onSelect:function
    • Called when one or more options are selected. Use this callback to update your current selected state.

      Note: For multi-select ({@link SelectMenuComponentOptions.maxValues}), this doesn't get called immediately. It only gets called after clicking away from the select dropdown.

      Parameters

      Returns unknown

  • options: MessageSelectOptionData[]

    The array of options that can be selected. Same structure as MessageSelectOptionData from DJS

  • Optional placeholder?: string

    The placeholder text to display when no options are selected

  • Optional selected?: Iterable<string> | string

    The currently selected option value(s). This accepts Iterable, so you can pass an array, a Set, or any other kind of iterable.

    see

    selectMenuComponent

SelectMenuInteractionContext

SelectMenuInteractionContext: InteractionContext & { message: Message; values: string[] }

Context object passed to {@link SelectMenuComponentOptions.onSelect}

SlashCommandConfig

SlashCommandConfig<Options>: { aliases?: string[]; description: string; name: string; options?: Options; run: any }

Configuration for a slash command. See Gatekeeper.addSlashCommand

Type parameters

Type declaration

  • Optional aliases?: string[]

    Aliases: alternate names to call this command with

  • description: string

    The description of the command. Shows up when showing a list of the bot's commands

  • name: string

    The name of the command. e.g. If you pass the name "airhorn", the command will be run with /airhorn in Discord

  • Optional options?: Options

    An object of options for the command, also called arguments, or parameters.

  • run:function

SlashCommandInteractionContext

SlashCommandInteractionContext<Options>: InteractionContext & { options: SlashCommandOptionValues<Options> }

The interaction context for a slash command

Type parameters

SlashCommandMentionableValue

SlashCommandMentionableValue: { mention: string } & ({ guildMember: GuildMember | undefined; isUser: true; user: User } | { isUser: false; role: Role })

A resolved mentionable option for a slash command

SlashCommandOptionChoiceConfig

SlashCommandOptionChoiceConfig<Value>: { name: string; value: Value }

A potential choice for a slash command option

Type parameters

  • Value

Type declaration

  • name: string
  • value: Value

SlashCommandOptionConfig

SlashCommandOptionConfig: SlashCommandOptionConfigBase & ({ choices?: SlashCommandOptionChoiceConfig<string>[]; type: "STRING" } | { choices?: SlashCommandOptionChoiceConfig<number>[]; type: "NUMBER" | "INTEGER" } | { type: "BOOLEAN" } | { type: "USER" } | { channelTypes?: SlashCommandOptionChannelType[]; type: "CHANNEL" } | { type: "ROLE" } | { type: "MENTIONABLE" })

A possible option for a slash command. See SlashCommandOptionValueMap for a list of possible options and the values they resolve to.

SlashCommandOptionConfigBase

SlashCommandOptionConfigBase: { description: string; required?: boolean }

Shared properties for all slash command option types

Type declaration

  • description: string

    Description for the option, shows up when tabbing through the options in Discord

  • Optional required?: boolean

    Whether the option is required. If true, the value will be guaranteed to exist in the options object, otherwise it will be undefined

SlashCommandOptionConfigMap

SlashCommandOptionConfigMap: {}

Valid slash command option config, only used for typescript inference

Type declaration

SlashCommandOptionValueMap

SlashCommandOptionValueMap: { BOOLEAN: boolean; CHANNEL: GuildChannel; INTEGER: number; MENTIONABLE: SlashCommandMentionableValue; NUMBER: number; ROLE: Role; STRING: string; USER: User }

A map of option types to the kind of value it resolves to. e.g. If an option has a type of "NUMBER", it will resolve to a number.

Type declaration

  • BOOLEAN: boolean
  • CHANNEL: GuildChannel
  • INTEGER: number
  • MENTIONABLE: SlashCommandMentionableValue
  • NUMBER: number
  • ROLE: Role
  • STRING: string
  • USER: User

SlashCommandOptionValues

SlashCommandOptionValues<Options>: { [ Name in keyof Options]: Options[Name]["required"] extends true ? SlashCommandOptionValueMap[Options[Name]["type"]] : SlashCommandOptionValueMap[Options[Name]["type"]] | undefined }

This is the magic that takes your option config and gives you a typesafe object of values.

Type parameters

TextComponent

TextComponent: { text: string; type: "text" }

Represents the text in a message

Type declaration

  • text: string
  • type: "text"

TopLevelComponent

A gatekeeper-specific type representing top-level components, stuff that doesn't need an extra wrapper.

For example, a button isn't top level, as it needs to be wrapped in an action row

UserCommandConfig

UserCommandConfig: { aliases?: string[]; name: string; run: any }

Options for creating a user command. Shows when right-clicking on a user.

see

Gatekeeper.addUserCommand

Type declaration

UserCommandInteractionContext

UserCommandInteractionContext: InteractionContext & { targetGuildMember: GuildMember | undefined; targetUser: User }

Functions

actionRowComponent

  • A component that represents a Discord action row and follows the same limitations (max 5 buttons, max 1 select, can't mix both).

    You usually don't have to use this yourself; Gatekeeper will automatically create action rows for you. But if you have a specific structure in mind, you can still use this.

    context.reply(() => [
    // normally, these two buttons would be on the same line,
    // but you can use action row components to put them on different lines
    actionRowComponent(
    buttonComponent({
    // ...
    }),
    ),
    actionRowComponent(
    buttonComponent({
    // ...
    }),
    ),
    ])

    Parameters

    Returns ActionRowComponent

buttonComponent

embedComponent

  • embedComponent(embed: MessageEmbedOptions | MessageEmbed): EmbedComponent
  • Creates an embed component. Accepts MessageEmbedOptions, or a DJS MessageEmbed instance.

    context.reply(() => [
    embedComponent({
    title: "Your weather today 🌤",
    description: `Sunny, with a 12% chance of rain`,
    footer: {
    text: "Sourced from https://openweathermap.org/",
    },
    }),
    ])

    Parameters

    • embed: MessageEmbedOptions | MessageEmbed

    Returns EmbedComponent

linkComponent

selectMenuComponent

Generated using TypeDoc