CommandBuilder
extends Builder
in package
implements
JsonSerializable
uses
CommandAttributes
Helper class used to build application commands.
Tags
Table of Contents
Interfaces
- JsonSerializable
Properties
- $contexts : array<string|int, int>|null
- Interaction context(s) where the command can be used, only for globally-scoped commands.
- $default_member_permissions : string|null
- Set of permissions represented as a bit set.
- $default_permission : bool|null
- The default permission of the command. If true the command is enabled when the app is added to the guild. SOON DEPRECATED.
- $description : string|null
- Description of the command. should be empty if the type is not CHAT_INPUT.
- $integration_types : array<string|int, int>|null
- Interaction context(s) where the command can be used, only for globally-scoped commands.
- $name : string
- Name of the command.
- $options : array<string|int, Option>|null
- 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
- __get() : mixed
- Handles dynamic get calls onto the part.
- __set() : void
- Handles dynamic set calls onto the part.
- addContext() : self
- Adds a context to the command. (Only for globally-scoped commands).
- addIntegrationType() : self
- Adds an integration type to the command. (Only for globally-scoped commands).
- addOption() : self
- Adds an option to the command.
- clearOptions() : self
- Clear all options from the command.
- create() : Command
- Creates the command in the given repository.
- fromPart() : self
- Creates a new instance of the builder from a given Part.
- getOptions() : array<string|int, Option>
- Returns all the options in the command.
- jsonSerialize() : array<string|int, mixed>
- new() : static
- Creates a new command builder.
- removeContext() : self
- Removes a context from the command. (Only for globally-scoped commands).
- removeIntegrationType() : self
- Removes an integration type from the command. (Only for globally-scoped commands).
- removeOption() : self
- Removes an option from the command.
- setContext() : self
- Sets the contexts of the command. (Only for globally-scoped commands).
- setDefaultMemberPermissions() : self
- Sets the default member permissions of the command.
- setDefaultPermission() : self
- Sets the default permission of the command.
- setDescription() : self
- Sets the description of the command.
- setDescriptionLocalization() : self
- Sets the description of the command in another language.
- setDmPermission() : self
- Sets the DM permission of the command.
- setGuildId() : self
- Sets the guild ID of the command.
- setHandler() : self
- Sets the handler for the command.
- setName() : self
- Sets the name of the command.
- setNameLocalization() : self
- Sets the name of the command in another language.
- setNsfw() : self
- Sets the age restriction of the command.
- setType() : self
- Sets the type of the command.
- toArray() : array<string|int, mixed>
- Returns an array with all the options.
- checkForGetMutator() : string|false
- Checks if there is a get mutator present.
- checkForSetMutator() : string|false
- Checks if there is a set mutator present.
- getProperty() : mixed
- Gets a property on the parent part.
- setProperty() : void
- Sets an property on the parent part.
- studly() : string
- Converts a string to studlyCase.
Properties
$contexts
Interaction context(s) where the command can be used, only for globally-scoped commands.
protected
array<string|int, int>|null
$contexts
= null
$default_member_permissions
Set of permissions represented as a bit set.
protected
string|null
$default_member_permissions
= null
$default_permission
The default permission of the command. If true the command is enabled when the app is added to the guild. SOON DEPRECATED.
protected
bool|null
$default_permission
= null
$description
Description of the command. should be empty if the type is not CHAT_INPUT.
protected
string|null
$description
= null
$integration_types
Interaction context(s) where the command can be used, only for globally-scoped commands.
protected
array<string|int, int>|null
$integration_types
= null
$name
Name of the command.
protected
string
$name
$options
The parameters for the command, max 25. Only for Slash command (CHAT_INPUT).
protected
array<string|int, Option>|null
$options
= null
$type
Type of the command. The type defaults to 1.
protected
int
$type
= \Discord\Parts\Interactions\Command\Command::CHAT_INPUT
Methods
__get()
Handles dynamic get calls onto the part.
public
__get(string $key) : mixed
Parameters
- $key : string
-
The attributes key.
Tags
Return values
mixed —The value of the attribute.
__set()
Handles dynamic set calls onto the part.
public
__set(string $key, mixed $value) : void
Parameters
- $key : string
-
The attributes key.
- $value : mixed
-
The attributes value.
Tags
addContext()
Adds a context to the command. (Only for globally-scoped commands).
public
addContext(int $context) : self
Parameters
- $context : int
-
Context to add.
Tags
Return values
selfaddIntegrationType()
Adds an integration type to the command. (Only for globally-scoped commands).
public
addIntegrationType(int $integration_type) : self
Parameters
- $integration_type : int
-
The integration type to add. Must be one of GUILD_INSTALL (0) or USER_INSTALL (1).
Tags
Return values
selfaddOption()
Adds an option to the command.
public
addOption(Option $option) : self
Parameters
- $option : Option
-
The option.
Tags
Return values
selfclearOptions()
Clear all options from the command.
public
clearOptions() : self
Return values
selfcreate()
Creates the command in the given repository.
public
create(GlobalCommandRepository|GuildCommandRepository $repository) : Command
Parameters
- $repository : GlobalCommandRepository|GuildCommandRepository
Tags
Return values
CommandfromPart()
Creates a new instance of the builder from a given Part.
public
static fromPart(Part $part) : self
Parameters
- $part : Part
Return values
selfgetOptions()
Returns all the options in the command.
public
getOptions() : array<string|int, Option>
Return values
array<string|int, Option>jsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>new()
Creates a new command builder.
public
static new() : static
Return values
staticremoveContext()
Removes a context from the command. (Only for globally-scoped commands).
public
removeContext(int $context) : self
Parameters
- $context : int
-
Context to remove.
Tags
Return values
selfremoveIntegrationType()
Removes an integration type from the command. (Only for globally-scoped commands).
public
removeIntegrationType(int $integration_type) : self
Parameters
- $integration_type : int
-
The integration type to remove.
Tags
Return values
selfremoveOption()
Removes an option from the command.
public
removeOption(Option $option) : self
Parameters
- $option : Option
-
Option to remove.
Tags
Return values
selfsetContext()
Sets the contexts of the command. (Only for globally-scoped commands).
public
setContext(array<string|int, mixed>|null $contexts) : self
Parameters
- $contexts : array<string|int, mixed>|null
-
Interaction contexts where the command can be used.
Tags
Return values
selfsetDefaultMemberPermissions()
Sets the default member permissions of the command.
public
setDefaultMemberPermissions(string|int $permissions) : self
Parameters
- $permissions : string|int
-
Default member permission bits of the command.
Return values
selfsetDefaultPermission()
Sets the default permission of the command.
public
setDefaultPermission(bool|null $permission) : self
See CommandAttributes::setDefaultMemberPermissions().
Parameters
- $permission : bool|null
-
Default permission of the command
Return values
selfsetDescription()
Sets the description of the command.
public
setDescription(string $description) : self
Parameters
- $description : string
-
Description of the command
Tags
Return values
selfsetDescriptionLocalization()
Sets the description of the command in another language.
public
setDescriptionLocalization(string $locale, string|null $description) : self
Parameters
- $locale : string
-
Discord locale code.
- $description : string|null
-
Localized description of the command.
Tags
Return values
selfsetDmPermission()
Sets the DM permission of the command.
public
setDmPermission(bool $permission) : self
Parameters
- $permission : bool
-
DM permission of the command.
Return values
selfsetGuildId()
Sets the guild ID of the command.
public
setGuildId(int $guildId) : self
Parameters
- $guildId : int
-
Guild ID of the command.
Return values
selfsetHandler()
Sets the handler for the command.
public
setHandler(int $handler) : self
Parameters
- $handler : int
-
Handler to set.
Tags
Return values
selfsetName()
Sets the name of the command.
public
setName(string $name) : self
Parameters
- $name : string
-
Name of the command. Slash command names are lowercase.
Tags
Return values
selfsetNameLocalization()
Sets the name of the command in another language.
public
setNameLocalization(string $locale, string|null $name) : self
Parameters
- $locale : string
-
Discord locale code.
- $name : string|null
-
Localized name of the command. Slash command names are lowercase.
Tags
Return values
selfsetNsfw()
Sets the age restriction of the command.
public
setNsfw(bool $restricted) : self
Parameters
- $restricted : bool
-
Age restriction of the command.
Return values
selfsetType()
Sets the type of the command.
public
setType(int $type) : self
Parameters
- $type : int
-
Type of the command.
Tags
Return values
selftoArray()
Returns an array with all the options.
public
toArray() : array<string|int, mixed>
Use jsonSerialize
Tags
Return values
array<string|int, mixed>checkForGetMutator()
Checks if there is a get mutator present.
protected
checkForGetMutator(string $key) : string|false
Parameters
- $key : string
-
The property name to check.
Return values
string|false —Either a string if it is a method or false.
checkForSetMutator()
Checks if there is a set mutator present.
protected
checkForSetMutator(string $key) : string|false
Parameters
- $key : string
-
The property name to check.
Return values
string|false —Either a string if it is a method or false.
getProperty()
Gets a property on the parent part.
protected
getProperty(string $key) : mixed
Parameters
- $key : string
-
The name of the property.
Tags
Return values
mixed —Either the property if it exists or void.
setProperty()
Sets an property on the parent part.
protected
setProperty(string $key, mixed $value) : void
Parameters
- $key : string
-
The name of the property.
- $value : mixed
-
The value of the property.
studly()
Converts a string to studlyCase.
private
static studly(string $string) : string
This is a port of updated Laravel's implementation, a non-regex with static cache. This method is private static as we may move it outside this class in future.
Parameters
- $string : string
-
The string to convert.