DiscordPHP Documentation

CommandRegistry
in package

FinalYes

Registry for message command client commands and aliases.

Tags
since
10.49.0

Table of Contents

Properties

$aliases  : array<string, string>
Map of alias => command name.
$caseInsensitive  : bool
Whether command names/aliases should be treated case-insensitively.
$commands  : array<string, Command>
Map of command name => Command instance.

Methods

__construct()  : mixed
Creates a command registry instance.
add()  : void
Add a command to the registry.
addAlias()  : void
Add an alias for an existing command name.
aliases()  : array<string, string>
Return all registered aliases.
all()  : array<string, Command>
Return all registered commands.
get()  : Command|null
Retrieve a command by name or alias.
has()  : bool
Check whether a command or alias exists.
hasAlias()  : bool
Check whether an alias exists.
hasCommand()  : bool
Check whether a command exists.
remove()  : void
Remove a command from the registry.
removeAlias()  : void
Remove an alias.
normalize()  : string
Normalize a command/alias name according to the case sensitivity setting.

Properties

$aliases

Map of alias => command name.

protected array<string, string> $aliases = []

$caseInsensitive

Whether command names/aliases should be treated case-insensitively.

protected bool $caseInsensitive

Methods

__construct()

Creates a command registry instance.

public __construct([bool $caseInsensitive = false ]) : mixed
Parameters
$caseInsensitive : bool = false

Whether command names/aliases should be treated case-insensitively.

add()

Add a command to the registry.

public add(string $name, Command $command) : void
Parameters
$name : string

Command trigger name.

$command : Command

Command instance.

Tags
throws
RuntimeException

When a command with the same name already exists.

addAlias()

Add an alias for an existing command name.

public addAlias(string $alias, string $commandName) : void
Parameters
$alias : string

Alias name.

$commandName : string

Target command name.

aliases()

Return all registered aliases.

public aliases() : array<string, string>
Return values
array<string, string>

get()

Retrieve a command by name or alias.

public get(string $name) : Command|null
Parameters
$name : string

Command name or alias.

Return values
Command|null

The command instance or null if not found.

has()

Check whether a command or alias exists.

public has(string $name) : bool
Parameters
$name : string

Command or alias to check.

Return values
bool

hasAlias()

Check whether an alias exists.

public hasAlias(string $alias) : bool
Parameters
$alias : string

Alias to check.

Return values
bool

hasCommand()

Check whether a command exists.

public hasCommand(string $name) : bool
Parameters
$name : string

Command name to check.

Return values
bool

remove()

Remove a command from the registry.

public remove(string $name) : void

This does not remove any aliases pointing to this command, so they will become invalid until removed or updated.

Parameters
$name : string

Command trigger name.

removeAlias()

Remove an alias.

public removeAlias(string $alias) : void
Parameters
$alias : string

Alias to remove.

normalize()

Normalize a command/alias name according to the case sensitivity setting.

protected normalize(string $name) : string
Parameters
$name : string
Return values
string
On this page

Search results