Command
extends Part
in package
implements
Stringable
uses
CommandAttributes
Represents a command registered on the Discord servers.
Tags
Table of Contents
Interfaces
- Stringable
Constants
- CHAT_INPUT = 1
- Slash commands; a text-based command that shows up when a user types /
- MESSAGE = 3
- A UI-based command that shows up when you right click or tap on a message
- USER = 2
- A UI-based command that shows up when you right click or tap on a user
Properties
- $application_id : string
- $created : bool
- Is the part already created in the Discord servers?
- $guild : Guild|null
- $guild_id : string|null
- $id : string
- $scriptData : mixed
- Custom script data.
- $version : string
- $attributes : array<string|int, mixed>
- The parts attributes.
- $discord : Discord
- The Discord client.
- $factory : Factory
- The factory.
- $fillable : array<string|int, mixed>
- The parts fillable attributes.
- $hidden : array<string|int, mixed>
- Attributes that are hidden from debug info.
- $http : Http
- The HTTP client.
- $repositories : array<string|int, mixed>
- An array of repositories that can exist in a part.
- $repositories_cache : array<string|int, mixed>
- An array of repositories.
- $visible : array<string|int, mixed>
- Attributes which are visible from debug info.
Methods
- __construct() : mixed
- Create a new part instance.
- __debugInfo() : array<string|int, mixed>
- Handles debug calls from var_dump and similar functions.
- __get() : mixed
- Handles dynamic get calls onto the part.
- __serialize() : array<string|int, mixed>
- __set() : void
- Handles dynamic set calls onto the part.
- __toString() : string
- Returns a formatted mention of the command.
- __unserialize() : void
- addOption() : $this
- Adds an option to the command.
- clearOptions() : $this
- Clear all options from the command.
- fetch() : PromiseInterface<string|int, static>
- Fetches any missing information about the part from Discord's servers.
- fill() : void
- Fills the parts attributes from an array.
- getCreatableAttributes() : array<string|int, mixed>
- getDiscord() : Discord
- Get the Discord instance that owns this Part.
- getPublicAttributes() : array<string|int, mixed>
- Returns an array of public attributes.
- getRawAttributes() : array<string|int, mixed>
- Returns an array of raw attributes.
- getRepositoryAttributes() : array<string|int, mixed>
- getUpdatableAttributes() : array<string|int, mixed>
- isPartial() : bool
- Whether the part is considered partial i.e. missing information which can be fetched from Discord.
- jsonSerialize() : array<string|int, mixed>
- Provides data when the part is encoded into JSON. Used for JsonSerializable.
- offsetExists() : bool
- Checks if an attribute exists via key. Used for ArrayAccess.
- offsetGet() : mixed
- Gets an attribute via key. Used for ArrayAccess.
- offsetSet() : void
- Sets an attribute via key. Used for ArrayAccess.
- offsetUnset() : void
- Unsets an attribute via key. Used for ArrayAccess.
- removeOption() : $this
- Removes an option from the command.
- serialize() : string|null
- Serializes the data. Used for Serializable.
- 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.
- 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.
- unserialize() : void
- Unserializes some data and stores it. Used for Serializable.
- afterConstruct() : void
- Called after the part has been constructed.
- getApplicationIdAttribute() : string
- Gets the application id attribute.
- getGuildAttribute() : Guild|null
- Returns the guild attribute.
- getOptionsAttribute() : CollectionInterface|array<string|int, Option>|null
- Gets the options attribute.
- makeOptionalAttributes() : array<string|int, mixed>
- Return key-value attributes if it has been filled.
- checkForGetMutator() : string|false
- Checks if there is a get mutator present.
- checkForSetMutator() : string|false
- Checks if there is a set mutator present.
- getAttribute() : mixed
- Gets an attribute on the part.
- setAttribute() : void
- Sets an attribute on the part.
- studly() : string
- Converts a string to studlyCase.
Constants
CHAT_INPUT
Slash commands; a text-based command that shows up when a user types /
public
mixed
CHAT_INPUT
= 1
MESSAGE
A UI-based command that shows up when you right click or tap on a message
public
mixed
MESSAGE
= 3
USER
A UI-based command that shows up when you right click or tap on a user
public
mixed
USER
= 2
Properties
$application_id
public
string
$application_id
The unique identifier of the parent Application that made the command, if made by one.
$created
Is the part already created in the Discord servers?
public
bool
$created
= false
Whether the part has been created.
$guild read-only
public
Guild|null
$guild
The guild that the command belongs to. Null if global.
$guild_id
public
string|null
$guild_id
The unique identifier of the guild that the command belongs to. Null if global.
$id
public
string
$id
The unique identifier of the command.
$scriptData
Custom script data.
Relying on this variable with dynamic caching is discouraged.
public
mixed
$scriptData
Used for storing custom information, used by end products.
$version
public
string
$version
Autoincrementing version identifier updated during substantial record changes.
$attributes
The parts attributes.
protected
array<string|int, mixed>
$attributes
= []
The parts attributes and content.
$discord
The Discord client.
protected
Discord
$discord
Client.
$factory
The factory.
protected
Factory
$factory
Factory.
$fillable
The parts fillable attributes.
protected
array<string|int, mixed>
$fillable
= ['id', 'type', 'application_id', 'guild_id', 'name', 'name_localizations', 'description', 'description_localizations', 'options', 'default_member_permissions', 'dm_permission', 'default_permission', 'nsfw', 'version']
The array of attributes that can be mass-assigned.
$hidden
Attributes that are hidden from debug info.
protected
array<string|int, mixed>
$hidden
= []
Attributes that are hidden from public.
$http
The HTTP client.
protected
Http
$http
Client.
$repositories
An array of repositories that can exist in a part.
protected
array<string|int, mixed>
$repositories
= []
Repositories.
$repositories_cache
An array of repositories.
protected
array<string|int, mixed>
$repositories_cache
= []
$visible
Attributes which are visible from debug info.
protected
array<string|int, mixed>
$visible
= []
Methods
__construct()
Create a new part instance.
public
__construct(Discord $discord[, array<string|int, mixed> $attributes = [] ][, bool $created = false ]) : mixed
Parameters
- $discord : Discord
-
The Discord client.
- $attributes : array<string|int, mixed> = []
-
An array of attributes to build the part.
- $created : bool = false
-
Whether the part has already been created.
__debugInfo()
Handles debug calls from var_dump and similar functions.
public
__debugInfo() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
__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.
__serialize()
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__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
__toString()
Returns a formatted mention of the command.
public
__toString() : string
Return values
string —A formatted mention of the command.
__unserialize()
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
addOption()
Adds an option to the command.
public
addOption(Option $option) : $this
Parameters
- $option : Option
-
The option.
Tags
Return values
$thisclearOptions()
Clear all options from the command.
public
clearOptions() : $this
Return values
$thisfetch()
Fetches any missing information about the part from Discord's servers.
public
fetch() : PromiseInterface<string|int, static>
Tags
Return values
PromiseInterface<string|int, static>fill()
Fills the parts attributes from an array.
public
fill(array<string|int, mixed> $attributes) : void
Parameters
- $attributes : array<string|int, mixed>
-
An array of attributes to build the part.
Tags
getCreatableAttributes()
public
getCreatableAttributes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getDiscord()
Get the Discord instance that owns this Part.
public
getDiscord() : Discord
Return values
DiscordgetPublicAttributes()
Returns an array of public attributes.
public
getPublicAttributes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
getRawAttributes()
Returns an array of raw attributes.
public
getRawAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed> —Raw attributes.
getRepositoryAttributes()
public
getRepositoryAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getUpdatableAttributes()
public
getUpdatableAttributes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>isPartial()
Whether the part is considered partial i.e. missing information which can be fetched from Discord.
public
isPartial() : bool
Return values
booljsonSerialize()
Provides data when the part is encoded into JSON. Used for JsonSerializable.
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of public attributes.
offsetExists()
Checks if an attribute exists via key. Used for ArrayAccess.
public
offsetExists(string $key) : bool
Parameters
- $key : string
-
The attribute key.
Return values
bool —Whether the offset exists.
offsetGet()
Gets an attribute via key. Used for ArrayAccess.
public
offsetGet(string $key) : mixed
Parameters
- $key : string
-
The attribute key.
Tags
Attributes
- #[ReturnTypeWillChange]
offsetSet()
Sets an attribute via key. Used for ArrayAccess.
public
offsetSet(string $key, mixed $value) : void
Parameters
- $key : string
-
The attribute key.
- $value : mixed
-
The attribute value.
Tags
offsetUnset()
Unsets an attribute via key. Used for ArrayAccess.
public
offsetUnset(string $key) : void
Parameters
- $key : string
-
The attribute key.
removeOption()
Removes an option from the command.
public
removeOption(Option $option) : $this
Parameters
- $option : Option
-
Option to remove.
Tags
Return values
$thisserialize()
Serializes the data. Used for Serializable.
public
serialize() : string|null
Return values
string|null —A string of serialized data.
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
$thissetDefaultPermission()
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
$thissetDescription()
Sets the description of the command.
public
setDescription(string $description) : $this
Parameters
- $description : string
-
Description of the command
Tags
Return values
$thissetDescriptionLocalization()
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
Return values
$thissetDmPermission()
Sets the DM permission of the command.
public
setDmPermission(bool $permission) : $this
Parameters
- $permission : bool
-
DM permission of the command.
Return values
$thissetGuildId()
Sets the guild ID of the command.
public
setGuildId(int $guildId) : $this
Parameters
- $guildId : int
-
Guild ID of the command.
Return values
$thissetName()
Sets the name of the command.
public
setName(string $name) : $this
Parameters
- $name : string
-
Name of the command. Slash command names are lowercase.
Tags
Return values
$thissetNameLocalization()
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
Return values
$thissetNsfw()
Sets the age restriction of the command.
public
setNsfw(bool $restricted) : $this
Parameters
- $restricted : bool
-
Age restriction of the command.
Return values
$thissetType()
Sets the type of the command.
public
setType(int $type) : $this
Parameters
- $type : int
-
Type of the command.
Tags
Return values
$thisunserialize()
Unserializes some data and stores it. Used for Serializable.
public
unserialize(string $data) : void
Parameters
- $data : string
-
Some serialized data.
Tags
afterConstruct()
Called after the part has been constructed.
protected
afterConstruct() : void
getApplicationIdAttribute()
Gets the application id attribute.
protected
getApplicationIdAttribute() : string
Return values
string —Application ID of this Bot if not set.
getGuildAttribute()
Returns the guild attribute.
protected
getGuildAttribute() : Guild|null
Return values
Guild|null —The guild attribute. null
for global command.
getOptionsAttribute()
Gets the options attribute.
protected
getOptionsAttribute() : CollectionInterface|array<string|int, Option>|null
Return values
CollectionInterface|array<string|int, Option>|null —A collection of options.
makeOptionalAttributes()
Return key-value attributes if it has been filled.
protected
makeOptionalAttributes(array<string|int, mixed> $attributes) : array<string|int, mixed>
To be used with fields marked "optional?" from the API.
Parameters
- $attributes : array<string|int, mixed>
-
Names of optional attribute
Return values
array<string|int, mixed>checkForGetMutator()
Checks if there is a get mutator present.
private
checkForGetMutator(string $key) : string|false
Parameters
- $key : string
-
The attribute name to check.
Tags
Return values
string|false —Either a string if it is a method or false.
checkForSetMutator()
Checks if there is a set mutator present.
private
checkForSetMutator(string $key) : string|false
Parameters
- $key : string
-
The attribute name to check.
Tags
Return values
string|false —Either a string if it is a method or false.
getAttribute()
Gets an attribute on the part.
private
getAttribute(string $key) : mixed
Parameters
- $key : string
-
The key to the attribute.
Tags
Return values
mixed —Either the attribute if it exists or void.
setAttribute()
Sets an attribute on the part.
private
setAttribute(string $key, mixed $value) : void
Parameters
- $key : string
-
The key to the attribute.
- $value : mixed
-
The value of the attribute.
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. The Discord\studly() is kept due to unintended bug and we do not want to introduce BC by replacing it. This method is private static as we may move it outside this class in future.
Parameters
- $string : string
-
The string to convert.