Option
extends Part
in package
Option represents an array of options that can be given to a command.
Tags
Table of Contents
Constants
- ATTACHMENT : mixed = 11
- Attachment object.
- BOOLEAN : mixed = 5
- CHANNEL : mixed = 7
- Includes all channel types + categories.
- INTEGER : mixed = 4
- Any integer between -2^53+1 and 2^53-1.
- MENTIONABLE : mixed = 9
- Includes users and roles.
- NUMBER : mixed = 10
- Any double between -2^53 and 2^53.
- ROLE : mixed = 8
- STRING : mixed = 3
- SUB_COMMAND : mixed = 1
- SUB_COMMAND_GROUP : mixed = 2
- SUPPORTED_AUDIO_EXTENSIONS : mixed = \Discord\Parts\Channel\Message\FileUpload::SUPP...
- Natively supported audio file extensions. Subject to change.
- SUPPORTED_FILE_TYPES : mixed = \Discord\Parts\Channel\Message\FileUpload::SUPP...
- Supported file types.
- SUPPORTED_IMAGE_EXTENSIONS : mixed = \Discord\Parts\Channel\Message\FileUpload::SUPP...
- Natively supported image file extensions. Subject to change.
- SUPPORTED_VIDEO_EXTENSIONS : mixed = \Discord\Parts\Channel\Message\FileUpload::SUPP...
- Natively supported video file extensions. Subject to change.
- USER : mixed = 6
Properties
- $autocomplete : bool|null
- $channel_types : array<string|int, mixed>|null
- $choices : ExCollectionInterface<string|int, Choice>|array<string|int, Choice>
- $created : bool
- Is the part already created in the Discord servers?
- $description : string
- $file_types : array<string|int, string>|null
- $max_length : int|null
- $max_value : int|float|null
- $min_length : int|null
- $min_value : int|float|null
- $name : string
- $options : ExCollectionInterface<string|int, Option>|array<string|int, Option>
- $required : bool|null
- $scriptData : mixed
- Custom script data.
- $type : int
- $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>
- __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
- Converts the part to a string.
- __unserialize() : void
- addChoice() : self
- Adds a choice to the option (Only for slash commands).
- addChoices() : self
- Adds multiple choices to the option (Only for slash commands).
- addOption() : self
- Adds an option to the option.
- addOptions() : self
- Adds multiple options to the option.
- 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.
- getConstants() : array<string|int, mixed>
- Returns an array of constant names and their values.
- getCreatableAttributes() : array<string|int, mixed>
- Returns the attributes needed to create.
- 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.
- getRepository() : AbstractRepository|null
- Gets the originating repository of the part.
- getRepositoryAttributes() : array<string|int, mixed>
- Gets the attributes to pass to repositories.
- getUpdatableAttributes() : array<string|int, mixed>
- Returns the updatable attributes.
- isPartial() : bool
- Whether the part is considered partial i.e. missing information which can be fetched from Discord.
- jsonSerialize() : array<string|int, mixed>
- 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.
- removeChoice() : self
- Removes a choice (Only for slash commands).
- removeOption() : self
- Removes an option.
- save() : PromiseInterface<string|int, Part>
- Save the part with its originating repository.
- serialize() : string|null
- Serializes the data. Used for Serializable.
- setAutoComplete() : self
- Sets the autocomplete interactions for this option.
- setChannelTypes() : self
- Sets the channel types of the option.
- setChoices() : self
- Sets multiple choices to the option (Only for slash commands).
- setDescription() : self
- Sets the description of the option.
- setDescriptionLocalization() : self
- Sets the description of the option in another language.
- setFileTypes() : self
- Sets the supported file types for uploaded files. Use image, video, audio, or dot-prefixed extensions like .pdf.
- setMaxLength() : self
- Sets the maximum length permitted.
- setMaxValue() : self
- Sets the maximum value permitted.
- setMinLength() : self
- Sets the minimum length permitted.
- setMinValue() : self
- Sets the minimum value permitted.
- setName() : self
- Sets the name of the option.
- setNameLocalization() : self
- Sets the name of the option in another language.
- setOptions() : self
- Sets multiple options to the option.
- setRequired() : self
- Sets the requirement of the option.
- setType() : self
- Sets the type of the option.
- unserialize() : void
- Unserializes some data and stores it. Used for Serializable.
- afterConstruct() : void
- Called after the part has been constructed.
- attributeCarbonHelper() : Carbon|null
- Helps with getting ISO8601 timestamp attributes.
- attributeCollectionHelper() : ExCollectionInterface
- Helps with getting Part attributes.
- attributePartHelper() : Part|null
- Helps with getting Part attributes.
- attributeTypedCollectionHelper() : ExCollectionInterface
- Helps with getting Part attributes for classes with extended types.
- 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.
- getChoicesAttribute() : ExCollectionInterface<string|int, Choice>|array<string|int, Choice>
- Gets the choices attribute.
- getOptionsAttribute() : ExCollectionInterface<string|int, Option>|array<string|int, Option>
- Gets the options attribute.
- makeOptionalAttributes() : array<string|int, mixed>
- Return key-value attributes if it has been filled.
- setAttribute() : void
- Sets an attribute on the part.
- studly() : string
- Converts a string to studlyCase.
Constants
ATTACHMENT
Attachment object.
public
mixed
ATTACHMENT
= 11
BOOLEAN
public
mixed
BOOLEAN
= 5
CHANNEL
Includes all channel types + categories.
public
mixed
CHANNEL
= 7
INTEGER
Any integer between -2^53+1 and 2^53-1.
public
mixed
INTEGER
= 4
MENTIONABLE
Includes users and roles.
public
mixed
MENTIONABLE
= 9
NUMBER
Any double between -2^53 and 2^53.
public
mixed
NUMBER
= 10
ROLE
public
mixed
ROLE
= 8
STRING
public
mixed
STRING
= 3
SUB_COMMAND
public
mixed
SUB_COMMAND
= 1
SUB_COMMAND_GROUP
public
mixed
SUB_COMMAND_GROUP
= 2
SUPPORTED_AUDIO_EXTENSIONS
Natively supported audio file extensions. Subject to change.
public
mixed
SUPPORTED_AUDIO_EXTENSIONS
= \Discord\Parts\Channel\Message\FileUpload::SUPPORTED_AUDIO_EXTENSIONS
SUPPORTED_FILE_TYPES
Supported file types.
public
mixed
SUPPORTED_FILE_TYPES
= \Discord\Parts\Channel\Message\FileUpload::SUPPORTED_FILE_TYPES
SUPPORTED_IMAGE_EXTENSIONS
Natively supported image file extensions. Subject to change.
public
mixed
SUPPORTED_IMAGE_EXTENSIONS
= \Discord\Parts\Channel\Message\FileUpload::SUPPORTED_IMAGE_EXTENSIONS
SUPPORTED_VIDEO_EXTENSIONS
Natively supported video file extensions. Subject to change.
public
mixed
SUPPORTED_VIDEO_EXTENSIONS
= \Discord\Parts\Channel\Message\FileUpload::SUPPORTED_VIDEO_EXTENSIONS
USER
public
mixed
USER
= 6
Properties
$autocomplete
public
bool|null
$autocomplete
Enable autocomplete interactions for this option.
$channel_types
public
array<string|int, mixed>|null
$channel_types
If the option is a channel type, the channels shown will be restricted to these types.
$choices
public
ExCollectionInterface<string|int, Choice>|array<string|int, Choice>
$choices
Choices for STRING, INTEGER, and NUMBER types for the user to pick from, max 25. Only for slash commands.
$created
Is the part already created in the Discord servers?
public
bool
$created
= false
Whether the part has been created.
$description
public
string
$description
1-100 character description.
$file_types
public
array<string|int, string>|null
$file_types
If the option is an ATTACHMENT type, the attachment types shown will be restricted to these types.
$max_length
public
int|null
$max_length
For option type STRING, the maximum allowed length (minimum of 1, maximum of 6000).
$max_value
public
int|float|null
$max_value
If the option is an INTEGER or NUMBER type, the maximum value permitted.
$min_length
public
int|null
$min_length
For option type STRING, the minimum allowed length (minimum of 0, maximum of 6000).
$min_value
public
int|float|null
$min_value
If the option is an INTEGER or NUMBER type, the minimum value permitted.
$name
public
string
$name
Name of the option.
$options
public
ExCollectionInterface<string|int, Option>|array<string|int, Option>
$options
Sub-options if applicable.
$required
public
bool|null
$required
If the parameter is required or optional--default false.
$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.
$type
public
int
$type
Type of the option.
$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
= ['type', 'name', 'name_localizations', 'description', 'description_localizations', 'required', 'choices', 'options', 'channel_types', 'min_value', 'max_value', 'min_length', 'max_length', 'autocomplete', 'file_types']
The array of attributes that can be mass-assigned.
Tags
$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()
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>__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()
Converts the part to a string.
public
__toString() : string
Tags
Return values
string —A JSON string of attributes.
__unserialize()
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
addChoice()
Adds a choice to the option (Only for slash commands).
public
addChoice(Choice $choice) : self
Parameters
- $choice : Choice
-
The choice.
Tags
Return values
selfaddChoices()
Adds multiple choices to the option (Only for slash commands).
public
addChoices(array<string|int, Choice> $choices) : self
Parameters
- $choices : array<string|int, Choice>
-
The choices.
Tags
Return values
selfaddOption()
Adds an option to the option.
public
addOption(Option $option) : self
Parameters
- $option : Option
-
The option.
Tags
Return values
selfaddOptions()
Adds multiple options to the option.
public
addOptions(array<string|int, Option> $options) : self
Parameters
- $options : array<string|int, Option>
-
The options.
Tags
Return values
selffetch()
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
getConstants()
Returns an array of constant names and their values.
public
getConstants() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An associative array where keys are constant names and values are their values.
getCreatableAttributes()
Returns the attributes needed to create.
public
getCreatableAttributes() : array<string|int, mixed>
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.
getRepository()
Gets the originating repository of the part.
public
getRepository() : AbstractRepository|null
Tags
Return values
AbstractRepository|null —The repository, or null if required part data is missing.
getRepositoryAttributes()
Gets the attributes to pass to repositories.
public
getRepositoryAttributes() : array<string|int, mixed>
Note: The order matters for repository tree (top to bottom).
Return values
array<string|int, mixed> —Attributes.
getUpdatableAttributes()
Returns the updatable attributes.
public
getUpdatableAttributes() : array<string|int, mixed>
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()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>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.
removeChoice()
Removes a choice (Only for slash commands).
public
removeChoice(string|Choice $choice) : self
Parameters
- $choice : string|Choice
-
Choice object or name to remove.
Return values
selfremoveOption()
Removes an option.
public
removeOption(string|Option $option) : self
Parameters
- $option : string|Option
-
Option object or name to remove.
Return values
selfsave()
Save the part with its originating repository.
public
save([string|null $reason = null ]) : PromiseInterface<string|int, Part>
Parameters
- $reason : string|null = null
-
The reason for the audit log, if supported.
Tags
Return values
PromiseInterface<string|int, Part> —Resolves with the saved part.
serialize()
Serializes the data. Used for Serializable.
public
serialize() : string|null
Return values
string|null —A string of serialized data.
setAutoComplete()
Sets the autocomplete interactions for this option.
public
setAutoComplete(bool|null $autocomplete) : self
Parameters
- $autocomplete : bool|null
-
enable autocomplete interactions for this option.
Tags
Return values
selfsetChannelTypes()
Sets the channel types of the option.
public
setChannelTypes(array<string|int, mixed>|null $types) : self
Parameters
- $types : array<string|int, mixed>|null
-
types of the channel.
Return values
selfsetChoices()
Sets multiple choices to the option (Only for slash commands).
public
setChoices([array<string|int, Choice> $choices = [] ]) : self
Parameters
- $choices : array<string|int, Choice> = []
-
The choices.
Tags
Return values
selfsetDescription()
Sets the description of the option.
public
setDescription(string $description) : self
Parameters
- $description : string
-
description of the option.
Tags
Return values
selfsetDescriptionLocalization()
Sets the description of the option in another language.
public
setDescriptionLocalization(string $locale, string|null $description) : self
Parameters
- $locale : string
-
Discord locale code.
- $description : string|null
-
Localized description of the option.
Tags
Return values
selfsetFileTypes()
Sets the supported file types for uploaded files. Use image, video, audio, or dot-prefixed extensions like .pdf.
public
setFileTypes([array<string|int, string>|null $file_types = null ]) : self
Discord recommends using the provided file groups. If you are specifying only extensions, you must include .jpg for image uploads, and both .mp4 and .mov for video uploads, due to mobile shenanigans.
No validation is done to ensure that the file types are valid. You are responsible for checking MIME types and file extensions.
Parameters
- $file_types : array<string|int, string>|null = null
-
Supported file types for uploaded files.
Tags
Return values
selfsetMaxLength()
Sets the maximum length permitted.
public
setMaxLength(int|null $max_length) : self
Parameters
- $max_length : int|null
-
For option type
STRING, the maximum allowed length (minimum of1).
Tags
Return values
selfsetMaxValue()
Sets the maximum value permitted.
public
setMaxValue(int|float|null $max_value) : self
Parameters
- $max_value : int|float|null
-
integer for INTEGER options, double for NUMBER options
Return values
selfsetMinLength()
Sets the minimum length permitted.
public
setMinLength(int|null $min_length) : self
Parameters
- $min_length : int|null
-
For option type
STRING, the minimum allowed length (minimum of0).
Tags
Return values
selfsetMinValue()
Sets the minimum value permitted.
public
setMinValue(int|float|null $min_value) : self
Parameters
- $min_value : int|float|null
-
integer for INTEGER options, double for NUMBER options.
Return values
selfsetName()
Sets the name of the option.
public
setName(string $name) : self
CHAT_INPUT command option names must match the following regex ^[\w-]{1,32}$ with the unicode flag set. If there is a lowercase variant of any letters used, you must use those. Characters with no lowercase variants and/or uncased letters are still allowed.
Parameters
- $name : string
-
name of the option. Slash command option names are lowercase.
Tags
Return values
selfsetNameLocalization()
Sets the name of the option in another language.
public
setNameLocalization(string $locale, string|null $name) : self
CHAT_INPUT command option names must match the following regex ^[\w-]{1,32}$ with the unicode flag set. If there is a lowercase variant of any letters used, you must use those. Characters with no lowercase variants and/or uncased letters are still allowed.
Parameters
- $locale : string
-
Discord locale code.
- $name : string|null
-
Localized name of the option. Slash command option names are lowercase.
Tags
Return values
selfsetOptions()
Sets multiple options to the option.
public
setOptions([array<string|int, Option> $options = [] ]) : self
Parameters
- $options : array<string|int, Option> = []
-
The options.
Tags
Return values
selfsetRequired()
Sets the requirement of the option.
public
setRequired([bool $required = false ]) : self
Parameters
- $required : bool = false
-
requirement of the option (default false)
Return values
selfsetType()
Sets the type of the option.
public
setType(int $type) : self
Parameters
- $type : int
-
type of the option.
Tags
Return values
selfunserialize()
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
attributeCarbonHelper()
Helps with getting ISO8601 timestamp attributes.
protected
attributeCarbonHelper(string $key) : Carbon|null
Parameters
- $key : string
-
The attribute key.
Tags
Return values
Carbon|nullattributeCollectionHelper()
Helps with getting Part attributes.
protected
attributeCollectionHelper(string $key, string $class[, string|null $discrim = 'id' ][, array<string|int, mixed>|null $extraData = [] ]) : ExCollectionInterface
Parameters
- $key : string
-
The attribute key.
- $class : string
-
The attribute class.
- $discrim : string|null = 'id'
-
The attribute discriminator.
- $extraData : array<string|int, mixed>|null = []
Tags
Return values
ExCollectionInterfaceattributePartHelper()
Helps with getting Part attributes.
protected
attributePartHelper(string $key, string $class[, array<string|int, mixed> $extraData = [] ]) : Part|null
Parameters
- $key : string
-
The attribute key.
- $class : string
-
The attribute class.
- $extraData : array<string|int, mixed> = []
-
Extra data to pass to the part constructor.
Tags
Return values
Part|nullattributeTypedCollectionHelper()
Helps with getting Part attributes for classes with extended types.
protected
attributeTypedCollectionHelper(string $class, string $key) : ExCollectionInterface
Parameters
- $class : string
-
The attribute class.
- $key : string
-
The attribute key.
Return values
ExCollectionInterfacecheckForGetMutator()
Checks if there is a get mutator present.
protected
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.
protected
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.
protected
getAttribute(string $key) : mixed
Parameters
- $key : string
-
The key to the attribute.
Tags
Return values
mixed —Either the attribute if it exists or void.
getChoicesAttribute()
Gets the choices attribute.
protected
getChoicesAttribute() : ExCollectionInterface<string|int, Choice>|array<string|int, Choice>
Return values
ExCollectionInterface<string|int, Choice>|array<string|int, Choice> —A collection of choices.
getOptionsAttribute()
Gets the options attribute.
protected
getOptionsAttribute() : ExCollectionInterface<string|int, Option>|array<string|int, Option>
Return values
ExCollectionInterface<string|int, Option>|array<string|int, Option> —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>setAttribute()
Sets an attribute on the part.
protected
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.