DiscordPHP Documentation

CommandBuilder extends Builder
in package
implements JsonSerializable uses CommandAttributes

Helper class used to build application commands.

Tags
since
7.0.0
author

Mark PeanutNL Versluis

Table of Contents

Interfaces

JsonSerializable

Properties

$default_permission  : bool
The default permission of the command. If true the command is enabled when the app is added to the guild.
$description  : string|null
Description of the command. should be empty if the type is not CHAT_INPUT.
$name  : string
Name of the command.
$options  : mixed
The parameters for the command, max 25. Only for Slash command (CHAT_INPUT).
$type  : int
Type of the command. The type defaults to 1.

Methods

addContext()  : $this
Adds a context to the command. (Only for globally-scoped commands)
addIntegrationType()  : $this
Adds an integration type to the command. (Only for globally-scoped commands)
addOption()  : $this
Adds an option to the command.
clearOptions()  : $this
Clear all options from the command.
fromPart()  : self
Creates a new instance of the builder from a given Part.
getOptions()  : ExCollectionInterface<string|int, Option>|array<string|int, Option>|null
Returns all the options in the command.
jsonSerialize()  : array<string|int, mixed>
{@inheritDoc}
new()  : static
Creates a new command builder.
removeContext()  : $this
Removes a context from the command. (Only for globally-scoped commands)
removeIntegrationType()  : $this
Removes an integration type from the command. (Only for globally-scoped commands)
removeOption()  : $this
Removes an option from the command.
setContextPermissions()  : $this
Sets the contexts of the command. (Only for globally-scoped commands)
setDefaultMemberPermissions()  : $this
Sets the default member permissions of the command.
setDefaultPermission()  : $this
Sets the default permission of the command.
setDescription()  : $this
Sets the description of the command.
setDescriptionLocalization()  : $this
Sets the description of the command in another language.
setDmPermission()  : $this
Sets the DM permission of the command.
setGuildId()  : $this
Sets the guild ID of the command.
setHandler()  : $this
Sets the handler for the command.
setName()  : $this
Sets the name of the command.
setNameLocalization()  : $this
Sets the name of the command in another language.
setNsfw()  : $this
Sets the age restriction of the command.
setType()  : $this
Sets the type of the command.
toArray()  : array<string|int, mixed>
Returns an array with all the options.

Properties

$default_permission

The default permission of the command. If true the command is enabled when the app is added to the guild.

protected bool $default_permission = true

$description

Description of the command. should be empty if the type is not CHAT_INPUT.

protected string|null $description = null

$options

The parameters for the command, max 25. Only for Slash command (CHAT_INPUT).

protected mixed $options = null
Tags
@var

ExCollectionInterface<Option|Option[]|null

$type

Type of the command. The type defaults to 1.

protected int $type = \Discord\Parts\Interactions\Command\Command::CHAT_INPUT

Methods

addContext()

Adds a context to the command. (Only for globally-scoped commands)

public addContext(int $context) : $this
Parameters
$context : int

Context to add.

Tags
throws
DomainException

If the command is not globally-scoped.

Return values
$this

addIntegrationType()

Adds an integration type to the command. (Only for globally-scoped commands)

public addIntegrationType(int $integration_type) : $this
Parameters
$integration_type : int

The integration type to add. Must be one of GUILD_INSTALL (0) or USER_INSTALL (1).

Tags
throws
DomainException

If the command is not globally-scoped or if an invalid integration type is provided.

Return values
$this

addOption()

Adds an option to the command.

public addOption(Option $option) : $this
Parameters
$option : Option

The option.

Tags
throws
DomainException

Command type is not CHAT_INPUT (1).

throws
OverflowException

Command exceeds maximum 25 options.

Return values
$this

clearOptions()

Clear all options from the command.

public clearOptions() : $this
Return values
$this

fromPart()

Creates a new instance of the builder from a given Part.

public static fromPart(Part $part) : self
Parameters
$part : Part
Return values
self

jsonSerialize()

{@inheritDoc}

public jsonSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

new()

Creates a new command builder.

public static new() : static
Return values
static

removeContext()

Removes a context from the command. (Only for globally-scoped commands)

public removeContext(int $context) : $this
Parameters
$context : int

Context to remove.

Tags
throws
DomainException

If the command is not globally-scoped.

Return values
$this

removeIntegrationType()

Removes an integration type from the command. (Only for globally-scoped commands)

public removeIntegrationType(int $integration_type) : $this
Parameters
$integration_type : int

The integration type to remove.

Tags
throws
DomainException

If the command is not globally-scoped.

Return values
$this

removeOption()

Removes an option from the command.

public removeOption(Option $option) : $this
Parameters
$option : Option

Option to remove.

Tags
throws
DomainException

Command type is not CHAT_INPUT (1).

Return values
$this

setContextPermissions()

Sets the contexts of the command. (Only for globally-scoped commands)

public setContextPermissions(array<string|int, mixed>|null $contexts) : $this
Parameters
$contexts : array<string|int, mixed>|null

Interaction contexts where the command can be used.

Tags
throws
DomainException

If the command is not globally-scoped.

Return values
$this

setDefaultMemberPermissions()

Sets the default member permissions of the command.

public setDefaultMemberPermissions(string|int $permissions) : $this
Parameters
$permissions : string|int

Default member permission bits of the command.

Return values
$this

setDefaultPermission()

Sets the default permission of the command.

public setDefaultPermission(bool|null $permission) : $this

See CommandAttributes::setDefaultMemberPermissions().

Parameters
$permission : bool|null

Default permission of the command

Return values
$this

setDescription()

Sets the description of the command.

public setDescription(string $description) : $this
Parameters
$description : string

Description of the command

Tags
throws
LengthException

$description is not 1-100 characters long.

Return values
$this

setDescriptionLocalization()

Sets the description of the command in another language.

public setDescriptionLocalization(string $locale, string|null $description) : $this
Parameters
$locale : string

Discord locale code.

$description : string|null

Localized description of the command.

Tags
throws
LengthException

$description is not 1-100 characters long.

Return values
$this

setDmPermission()

Sets the DM permission of the command.

public setDmPermission(bool $permission) : $this
Parameters
$permission : bool

DM permission of the command.

Return values
$this

setGuildId()

Sets the guild ID of the command.

public setGuildId(int $guildId) : $this
Parameters
$guildId : int

Guild ID of the command.

Return values
$this

setHandler()

Sets the handler for the command.

public setHandler(int $handler) : $this
Parameters
$handler : int

Handler to set.

Tags
throws
DomainException

Command type is not PRIMARY_ENTRY_POINT (4) or if the handler is not valid.

Return values
$this

setName()

Sets the name of the command.

public setName(string $name) : $this
Parameters
$name : string

Name of the command. Slash command names are lowercase.

Tags
throws
LengthException

$name is not 1-32 characters long.

throws
DomainException

$name contains invalid characters.

Return values
$this

setNameLocalization()

Sets the name of the command in another language.

public setNameLocalization(string $locale, string|null $name) : $this
Parameters
$locale : string

Discord locale code.

$name : string|null

Localized name of the command. Slash command names are lowercase.

Tags
throws
LengthException

$name is not 1-32 characters long.

throws
DomainException

$name contains invalid characters.

Return values
$this

setNsfw()

Sets the age restriction of the command.

public setNsfw(bool $restricted) : $this
Parameters
$restricted : bool

Age restriction of the command.

Return values
$this

setType()

Sets the type of the command.

public setType(int $type) : $this
Parameters
$type : int

Type of the command.

Tags
throws
InvalidArgumentException

$type is not 1-3.

Return values
$this

toArray()

Returns an array with all the options.

public toArray() : array<string|int, mixed>
Tags
throws
LengthException
throws
DomainException
Return values
array<string|int, mixed>

        
On this page

Search results