Results

Namespace

Type

Command groups contain categories of logically separated groups of commands.

Command Groups may specify filters that apply to all commands added to the group.

Commands must be added to command groups via one of the registration methods available.

Hierarchy

  • CommandGroup <-- You are here!

Implements

Index

Constructors

constructor

  • new CommandGroup(options?: ICommandGroupOptions): CommandGroup
  • Constructs a new command group. By default, this constructor will register message events and listen for messages that match commands added to the command group.

    Parameters

    Returns CommandGroup

Methods

attach

  • attach(executors: object): this
  • Attaches the command executors provided.

    For more examples, see discord.command.handler.

    Generally it is preferred to use on, raw and subcommand depending on how you wish to structure your module. Attach is generally more useful when you are importing un-attached commands from various modules, whereas on & company are useful if you want to define your command handlers in-line.

    Parameters

    • executors: object

      An object, keyed by the name that the command executor will use.

    Returns this

checkMessage

  • checkMessage(message: Message): Promise<boolean>
  • Determines if the command group will execute given the supplied message, without executing the command.

    Note: Use discord.command.CommandGroup.handleMessage to execute a command within the CommandGroup.

    Parameters

    Returns Promise<boolean>

default

defaultRaw

  • defaultRaw(handler: CommandHandler<string>, options?: Omit<ICommandOptions, "name">): this
  • Registers a command that will run for any un-matched commands that match the command group's prefix(es).

    All text proceeding the command name is passed to the handler in the "args" parameter as a string.

    Parameters

    • handler: CommandHandler<string>

      A function to be ran when command validation succeeds and the command should be executed.

    • Optional options: Omit<ICommandOptions, "name">

      Options for this default handler.

    Returns this

handleMessage

  • handleMessage(message: Message): Promise<boolean>
  • Manually executes the command group given a discord.Message. Useful if you specify { register: false } when instantiating a new CommandGroup.

    If the message is not to be handled by this command group (given the command prefix and command name) the Promise will resolve as false.

    If the message was otherwise handled and executed, it will otherwise resolve true.

    Note: Use discord.command.CommandGroup.checkMessage to check (without executing) if the CommandGroup will execute for the given message.

    Parameters

    Returns Promise<boolean>

    true if a command was handled and executed successfully. The function will throw if the command handler errors.

on

  • on<T>(options: string | ICommandOptions, parser: ArgumentsParser<T>, handler: CommandHandler<ResolvedArgs<T>>): this
  • Registers a command that expects arguments.

    If argument parsing/validation fails, an error will be returned to the user and the handler will not run.

    Example

    Creates a script that will have a command that returns a number that has been multiplied by 2, as !double N, where !double 4 would output 8

    const commandGroup = new discord.command.CommandGroup();
    commandGroup.on(
      'double',
      (ctx) => ({ n: ctx.integer() }),
      (message, { n }) => message.reply(`${n * 2}`)
    );

    Type parameters

    Parameters

    • options: string | ICommandOptions

      A string containing the name of the command, or an object with more options (including filters, description, etc).

    • parser: ArgumentsParser<T>

      A function that collects the argument types this command expects.

    • handler: CommandHandler<ResolvedArgs<T>>

      A function to be ran when command validation succeeds and the command should be executed.

    Returns this

raw

  • raw(options: string | ICommandOptions, handler: CommandHandler<string>): this
  • Registers a command that accepts any or no arguments.

    All text proceeding the command name is passed to the handler in the "args" parameter as a string.

    Example

    Creates a script that will reply with pong! when !ping is said in chat.

    const commandGroup = new discord.command.CommandGroup();
    commandGroup.raw("ping", message => message.reply("pong!"));

    Parameters

    • options: string | ICommandOptions

      A string containing the name of the command, or an object with more options (including filters, description, etc).

    • handler: CommandHandler<string>

      A function to be ran when command validation succeeds and the command should be executed.

    Returns this

registerCommand

setFilter

  • setFilter(filter?: ICommandFilter | null): this
  • Sets the filter(s) to be used for this command group. All child commands will use these filters.

    Note: Replaces any filters set previously.

    Parameters

    • Optional filter: ICommandFilter | null

      The filter composition to use for this command group.

    Returns this

subcommand

  • subcommand(options: string | Named<Omit<ICommandGroupOptions, "register">>, commandGroup: function): this
  • Registers a command that may be followed by additional nested command groups.

    This is useful to further organize and group commands within a single parent command group.

    Sub-command groups are just like Command Groups, and will require filters of all parent sub-commands to be passed before executing any sub-commands.

    Example:

    Creates a script that will have the following commands:

    • !lights on
    • !lights off
    const commandGroup = new discord.command.CommandGroup();
    commandGroup.subcommand("lights", subCommandGroup => {
     subCommandGroup.raw("on", m => m.reply("lights on turned on!"));
     subCommandGroup.raw("off", m => m.reply("lights turned off!"));
    });

    Parameters

    • options: string | Named<Omit<ICommandGroupOptions, "register">>

      A string containing the name of the command, or an object with more options. See discord.command.ICommandGroupOptions. The name property must be present, specifying the name of the subcommand-group. Sub-command groups may not be automatically registered, so the register property must not be set.

    • commandGroup: function

      A CommandGroup instance (must not be previously registered) or a function which passes a nested CommandGroup as the first parameter.

    Returns this

  • subcommand(options: string | Named<Omit<ICommandGroupOptions, "filters" | "register">>, commandGroup: CommandGroup): this
  • Deprecated - attach the subcommand group using attach instead.

    deprecated

    Parameters

    Returns this

subcommandGroup

  • subcommandGroup(options: string | Named<Omit<ICommandGroupOptions, "register">>): CommandGroup
  • Creates, registers and returns a sub-command group.

    This command is an alternate form of subcommand, that lets capture the sub-command's CommandGroup. For more on sub-commands, see the subcommand docs.

    Example:

    Creates a script that will have the following commands:

    • !lights on
    • !lights off
    const commandGroup = new discord.command.CommandGroup();
    const subCommandGroup = commandGroup.subcommandGroup("lights");
    subCommandGroup.raw("on", m => m.reply("lights on turned on!"));
    subCommandGroup.raw("off", m => m.reply("lights turned off!"));

    Parameters

    • options: string | Named<Omit<ICommandGroupOptions, "register">>

      An object containing the command group's options. Register is not able to be set, as the command group is implicitly registered as a sub-command for this command group.

    Returns CommandGroup

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc