Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CommandManager

Object that stores the registered commands and is responsible for data exchanging with the Discord API

Hierarchy

  • CommandManager

Index

Constructors

constructor

Properties

Private Readonly _commands

_commands: Command[] = []

List of commands registered in the manager

readonly

Private Readonly _globalEntryName

_globalEntryName: string = "global"

Private Readonly _registerCache

_registerCache: Map<string, Map<string, RegisteredCommandObject>> = ...

Cache of Discord API commands data

readonly

Readonly argumentSeparator

argumentSeparator: string

A string used to split all incoming input data from Discord messages

readonly

Readonly client

client: Bot

Client connected to this manager

readonly

Readonly commandSeparator

commandSeparator: string

A string used to separate subcommand groups and subcommands

readonly

Optional Readonly help

Help command associated with this manager

readonly

Readonly prefix

A manager holding all guild-specific prefixes and a global prefix

readonly

Static Readonly baseApiUrl

baseApiUrl: string = "https://discord.com/api/v8"

Discord API URL

static
readonly

Accessors

cache

commandsCount

  • get commandsCount(): number

Methods

add

  • Creates and registers command in the manager based on the given options

    remarks

    All commands have to be added to the instance before starting the bot. Adding commands while the bot is running is not possible and can cause issues.

    Command types

    • CHAT - message interactions using command prefixes or slash commands
    • USER - right-click context menu interactions on users
    • MESSAGE - right-click context menu interactions on messages

    Type parameters

    Parameters

    • type: T

      a type of command that will be created and added to this manager

    • options: CommandInit<T>

      an object containing all properties required to create this type of command

    Returns Commands<T>

    A computed command object that inherits from Command

Private arrayToMap

fetch

  • Process an interaction

    Parameters

    • i: Message | Interaction

      interaction object to fetch a command from

    Returns null | InputManager

    An InputManager containing all input data (command, arguments, target etc.)

get

getApi

Private getCache

getIdApi

  • getIdApi(name: string, type: APICommandType, guild?: string | Guild): Promise<null | string>
  • Fetches command ID by name from the Discord APi

    async

    Parameters

    • name: string

      name of the command

    • type: APICommandType

      command type you want to get ID for

    • Optional guild: string | Guild

    Returns Promise<null | string>

    Command ID from the Discord API

getPermissionsApi

  • Get permissions from Discord Permissions API for a specified command

    async
    experimental

    This functionality hasn't been polished and fully tested yet. Using it might lead to errors and application crashes.

    Parameters

    • id: string

      command ID

    • Optional g: string | Guild

    Returns Promise<CommandPermission[]>

list

listApi

register

  • register(): Promise<void>

setPermissionsApi

  • setPermissionsApi(id: string, permissions: CommandPermission[], g?: string | Guild): Promise<void>
  • Set permissions using Discord Permissions API

    async
    experimental

    This functionality hasn't been polished and fully tested yet. Using it might lead to errors and application crashes.

    Parameters

    • id: string

      command ID

    • permissions: CommandPermission[]

      permissions to set

    • Optional g: string | Guild

    Returns Promise<void>

Private updateCache

Static isCommand

Generated using TypeDoc