Command
Class that represents a single command and allows you to configure it.
Implements
MiddlewareObj<C>Type Parameters
C
Constructors
Command(
name: string | RegExp,
description: string,
handler: MaybeArray<Middleware<CommandContext<C>>>,
options?: Partial<CommandOptions>,
);Initialize a new command with a default handler.
[!IMPORTANT] This class by its own does nothing. It needs to be imported into a Command via the add method.
Command(
name: string | RegExp,
description: string,
options?: Partial<CommandOptions>,
);Initialize a new command with no handlers.
[!IMPORTANT] This class by its own does nothing. It needs to be imported into a Command via the add method
Command(
name: string | RegExp,
description: string,
handlerOrOptions?: MaybeArray<Middleware<CommandContext<C>>> | Partial<CommandOptions>,
options?: Partial<CommandOptions>,
);Command(
name: string | RegExp,
description: string,
handlerOrOptions?: MaybeArray<Middleware<CommandContext<C>>> | Partial<CommandOptions>,
options?: Partial<CommandOptions>,
);Methods
hasCustomPrefix (getter)
get hasCustomPrefix();
Whether the command has a custom prefix
stringName (getter)
get stringName();
Gets the command name as string
isApiCompliant
isApiCompliant();
Whether the command can be passed to a set API call and, if not, the reason.
scopes (getter)
get scopes();
Get registered scopes for this command
languages (getter)
get languages();
Get registered languages for this command
names (getter)
get names();
Get registered names for this command
name (getter)
get name();
Get the default name for this command
description (getter)
get description();
Get the default description for this command
prefix (getter)
get prefix();
Get the prefix for this command
hasHandler (getter)
get hasHandler();
Get if this command has a handler
isEphemeral (getter)
get isEphemeral();
Whether this command is ephemeral.
Ephemeral commands are highlighted with a special icon in the bot menu, and the user’s command message stays invisible to other group members.
ephemeral
ephemeral();
Marks this command as ephemeral. This adds is to the command when it is serialized for a set call.
By default, the handlers of an ephemeral command only run when the incoming command message was itself sent ephemerally. Pass { strict: to also run the handlers when the command is sent as a regular, non-ephemeral message.
Note: Some clients may send a command regularly if it is typed out rather than selected from the command menu.
addToScope
// Overload 1
addToScope();
// Overload 2
addToScope();
// Overload 3
addToScope();
Registers the command to a scope to allow it to be handled and used with set. This will automatically apply filtering middlewares for you, so the handler only runs on the specified scope.
localize
localize();
Adds a new translation for the command
getLocalizedName
getLocalizedName();
Gets the localized command name of an existing translation
getLocalizedDescription
getLocalizedDescription();
Gets the localized command name of an existing translation
toObject
toObject();
Converts command to an object representation. Useful for JSON serialization.
middleware
middleware();
Static Methods
findMatchingCommand
findMatchingCommand();
Finds the matching command in the given context
hasCommand
hasCommand();
Creates a matcher for the given command that can be used in filtering operations