RegisteredCommand
in package
RegisteredCommand represents a command that has been registered with the Discord servers and has a handler to handle when the command is triggered.
https://discord.com/developers/docs/interactions/application-commands
Tags
Table of Contents
Properties
- $discord : Discord
- The Discord client.
- $autocomplete_callback : callable
- The callback to be called when the auto complete is triggered.
- $callback : callable
- The callback to be called when the command is triggered.
- $name : string
- The name of the command.
- $subCommands : array<string|int, RegisteredCommand>
- Array of sub-commands.
Methods
- __construct() : mixed
- RegisteredCommand represents a command that has been registered with the Discord servers and has a handler to handle when the command is triggered.
- addSubCommand() : static
- Adds a sub-command to the command.
- execute() : bool
- Executes the command. Will search for a sub-command if given, otherwise executes the callback, if given.
- getName() : string
- Get command name.
- getSubCommand() : RegisteredCommand|null
- Tries to get a sub-command if exists.
- getSubCommands() : array<string|int, RegisteredCommand>|null
- Get sub commands.
- setAutoCompleteCallback() : void
- Sets the callback for the auto complete suggestion.
- setCallback() : void
- Sets the callback for the command.
- suggest() : bool
- Executes the command. Will search for a sub-command if given, otherwise executes the callback, if given.
Properties
$discord
The Discord client.
protected
Discord
$discord
Client.
$autocomplete_callback
The callback to be called when the auto complete is triggered.
private
callable
$autocomplete_callback
$callback
The callback to be called when the command is triggered.
private
callable
$callback
$name
The name of the command.
private
string
$name
$subCommands
Array of sub-commands.
private
array<string|int, RegisteredCommand>
$subCommands
Methods
__construct()
RegisteredCommand represents a command that has been registered with the Discord servers and has a handler to handle when the command is triggered.
public
__construct(Discord $discord, string $name[, callable|null $callback = null ][, callable|null $autocomplete_callback = null ]) : mixed
Parameters
- $discord : Discord
- $name : string
- $callback : callable|null = null
- $autocomplete_callback : callable|null = null
-
Callback returning list of auto complete suggestions
addSubCommand()
Adds a sub-command to the command.
public
addSubCommand(string|array<string|int, mixed> $name[, callable|null $callback = null ][, callable|null $autocomplete_callback = null ]) : static
Parameters
- $name : string|array<string|int, mixed>
- $callback : callable|null = null
- $autocomplete_callback : callable|null = null
Tags
Return values
staticexecute()
Executes the command. Will search for a sub-command if given, otherwise executes the callback, if given.
public
execute(ExCollectionInterface|array<string|int, Option> $options, Interaction $interaction) : bool
Parameters
- $options : ExCollectionInterface|array<string|int, Option>
- $interaction : Interaction
Return values
bool —Whether the command successfully executed.
getName()
Get command name.
public
getName() : string
Return values
stringgetSubCommand()
Tries to get a sub-command if exists.
public
getSubCommand(string $name) : RegisteredCommand|null
Parameters
- $name : string
Return values
RegisteredCommand|nullgetSubCommands()
Get sub commands.
public
getSubCommands() : array<string|int, RegisteredCommand>|null
Return values
array<string|int, RegisteredCommand>|nullsetAutoCompleteCallback()
Sets the callback for the auto complete suggestion.
public
setAutoCompleteCallback(callable $autocomplete_callback) : void
Parameters
- $autocomplete_callback : callable
setCallback()
Sets the callback for the command.
public
setCallback(callable $callback) : void
Parameters
- $callback : callable
suggest()
Executes the command. Will search for a sub-command if given, otherwise executes the callback, if given.
public
suggest(Interaction $interaction) : bool
Parameters
- $interaction : Interaction
Return values
bool —Whether the command successfully executed.