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(language?: LanguageCode | "default"): [true] | [false, string[]];
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
addToScope
// Overload 1
addToScope(
scope: BotCommandGroupsScope,
middleware?: MaybeArray<ChatTypeMiddleware<C, "group" | "supergroup">>,
options?: Partial<CommandOptions>,
): this;
// Overload 2
addToScope(
scope: BotCommandScopeAllPrivateChats,
middleware?: MaybeArray<ChatTypeMiddleware<C, "private">>,
options?: Partial<CommandOptions>,
): this;
// Overload 3
addToScope(
scope: BotCommandScope,
middleware?: MaybeArray<Middleware<C>>,
options?: Partial<CommandOptions>,
): this;
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(
languageCode: LanguageCode,
name: string | RegExp,
description: string,
);
Adds a new translation for the command
getLocalizedName
getLocalizedName(languageCode: LanguageCode | "default");
Gets the localized command name of an existing translation
getLocalizedDescription
getLocalizedDescription(languageCode: LanguageCode | "default");
Gets the localized command name of an existing translation
toObject
toObject(languageCode: LanguageCode | "default"): BotCommand;
Converts command to an object representation. Useful for JSON serialization.
middleware
middleware();
Static Methods
hasCommand
hasCommand(command: MaybeArray<string | RegExp>, options: CommandOptions);
Creates a matcher for the given command that can be used in filtering operations