Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Client<Ready>

An extension of the default Discord.js Client class that includes methods for the middleware-like command system

Type parameters

  • Ready: boolean = boolean

Hierarchy

  • Client<Ready>
    • Client

Index

Constructors

  • Type parameters

    • Ready: boolean = boolean

    Parameters

    Returns Client<Ready>

Properties

_stack: StackItem[] = []
slashCommand: (commands: string | string[], ...handlers: DiscordExpressInteractionCommandHandler[]) => void = ...

Type declaration

    • Add interaction command handlers to the middleware chain

      Functionally equivalent to interactionCommand

      remarks

      Using interactionCommand does not restrict you from handling message commands later. Only, these specific handler(s) will only run if the request came from an interaction command

      example
      client.interactionCommand("*") // Match all interaction commands
      client.interactionCommand("myCommand") // Match `myCommand`
      client.interactionCommand("mySubcommand/*") // Match all commands under `mySubcommand` AND `my-subcommand`

      // Match `mySubcommandGroup mySubcommand myCommand` AND `my-subcommand-group my-subcommand my-command`
      client.interactionCommand("mySubcommandGroup/mySubcommand/myCommand")

      Parameters

      Returns void

Methods

  • _getStack(request: Request, response: Response, nextFunction: (err?: unknown) => Promise<void>, errorRef: Ref<{ didHandle: boolean; error: unknown }>): AsyncGenerator<unknown, undefined, unknown>
  • Parameters

    • request: Request
    • response: Response
    • nextFunction: (err?: unknown) => Promise<void>
        • (err?: unknown): Promise<void>
        • Parameters

          • Optional err: unknown

          Returns Promise<void>

    • errorRef: Ref<{ didHandle: boolean; error: unknown }>

    Returns AsyncGenerator<unknown, undefined, unknown>

  • applyStack(trigger: Message<boolean> | Interaction<CacheType>): Promise<void>
  • Apply the router stack AKA middleware chain to the trigger. Normally, you shouldn't have to use this.

    Parameters

    • trigger: Message<boolean> | Interaction<CacheType>

    Returns Promise<void>

  • Add command handlers to the middleware chain

    example
    client.command("*") // Match all commands
    client.command("myCommand") // Match `myCommand`
    client.command("mySubcommand/*") // Match all commands under `mySubcommand` AND `my-subcommand`

    // Match `mySubcommandGroup mySubcommand myCommand` AND `my-subcommand-group my-subcommand my-command`
    client.command("mySubcommandGroup/mySubcommand/myCommand")

    Parameters

    • commands: string | string[]

      A command specifier, or array of command specifiers

    • Rest ...handlers: DiscordExpressHandler[]

      Handlers for this command

    Returns void

  • Handle any errors that may arise from the middleware chain

    remarks

    Only errors that occur BEFORE these handler(s) are defined will be handled. It is common practice to place error handlers at the very end of the middleware chain.

    Parameters

    Returns void

  • Handle errors in routes that may arise from the middleware chain

    remarks

    Only errors that occur BEFORE these handler(s) are defined will be handled. It is common practice to place error handlers at the very end of the middleware chain.

    Parameters

    • routes: string | string[]

      A command specifier, or array of command specifiers

    • Rest ...handlers: DiscordExpressErrorHandler[]

      Middleware handlers

    Returns void

  • initExpress(): void
  • Initialize the express portion of the client by adding event listeners to the messageCreate and interactionCreate events

    Returns void

  • Add interaction command handlers to the middleware chain

    remarks

    Using interactionCommand does not restrict you from handling message commands later. Only, these specific handler(s) will only run if the request came from an interaction command

    example
    client.interactionCommand("*") // Match all interaction commands
    client.interactionCommand("myCommand") // Match `myCommand`
    client.interactionCommand("mySubcommand/*") // Match all commands under `mySubcommand` AND `my-subcommand`

    // Match `mySubcommandGroup mySubcommand myCommand` AND `my-subcommand-group my-subcommand my-command`
    client.interactionCommand("mySubcommandGroup/mySubcommand/myCommand")

    Parameters

    Returns void

  • Add message command handlers to the middleware chain

    remarks

    Using messageCommand does not restrict you from handling interaction commands later. Only, these specific handler(s) will only run if the request came from a message command

    example
    client.messageCommand("*") // Match all message commands
    client.messageCommand("myCommand") // Match `myCommand`
    client.messageCommand("mySubcommand/*") // Match all commands under `mySubcommand` AND `my-subcommand`

    // Match `mySubcommandGroup mySubcommand myCommand` AND `my-subcommand-group my-subcommand my-command`
    client.messageCommand("mySubcommandGroup/mySubcommand/myCommand")

    Parameters

    • commands: string | string[]

      A command specifier, or array of command specifiers

    • Rest ...handlers: DiscordExpressMessageHandler[]

      Handlers for this message command

    Returns void

  • registerCommands(commands: RESTPostAPIApplicationCommandsJSONBody[], clientId: string): Promise<unknown>
  • Register Application Commands (slash commands). You can use the SlashCommandBuilder class if you prefer, or the implementation shipped with this library

    Parameters

    • commands: RESTPostAPIApplicationCommandsJSONBody[]

      Commands to register

    • clientId: string

      App client ID

    Returns Promise<unknown>

  • Use middleware universally

    Parameters

    Returns void

  • Use middleware for a specific route or command

    example
    client.use("*") // Match all commands
    client.use("myCommand") // Match `myCommand`
    client.use("mySubcommand/*") // Match all commands under `mySubcommand` AND `my-subcommand`

    // Match `mySubcommandGroup mySubcommand myCommand` AND `my-subcommand-group my-subcommand my-command`
    client.use("mySubcommandGroup/mySubcommand/myCommand")

    Parameters

    • routes: string | string[]

      A command specifier, or array of command specifiers

    • Rest ...handlers: DiscordExpressHandler[]

      Middleware handlers

    Returns void

Generated using TypeDoc