SelectMenu
extends Interactive
in package
Select menus are interactive components that allow users to select one or more options from a dropdown list in messages.
Use StringSelect
On desktop, clicking on a select menu opens a dropdown-style UI. On mobile, tapping a select menu opens up a half-sheet with the options.
Tags
Table of Contents
Constants
- TYPE_ACTION_ROW = 1
- TYPE_BUTTON = 2
- TYPE_CHANNEL_SELECT = 8
- TYPE_CONTAINER = 17
- TYPE_CONTENT_INVENTORY_ENTRY = 16
- TYPE_FILE = 13
- TYPE_LABEL = 18
- TYPE_MEDIA_GALLERY = 12
- TYPE_MENTIONABLE_SELECT = 7
- TYPE_ROLE_SELECT = 6
- TYPE_SECTION = 9
- TYPE_SELECT_MENU = 3
- TYPE_SEPARATOR = 14
- TYPE_STRING_SELECT = 3
- TYPE_TEXT_DISPLAY = 10
- TYPE_TEXT_INPUT = 4
- TYPE_THUMBNAIL = 11
- TYPE_USER_SELECT = 5
- USAGE = ['Message', 'Modal']
Properties
- $channel_types : array<string|int, mixed>|null
- List of channel types to include in the channel select component (type 8).
- $custom_id : string
- Custom ID to identify the select menu.
- $default_values : array<string|int, mixed>|null
- List of default values for auto-populated select menu components; number of default values must be in the range defined by min_values and max_values.
- $disabled : bool|null
- Whether the select menu should be disabled.
- $discord : Discord|null
- Discord instance when the listener is set.
- $id : int|null
- 32 bit integer used as an optional identifier for component.
- $listener : callable|null
- Callback used to listen for `INTERACTION_CREATE` events.
- $max_values : int|null
- Maximum number of options that must be selected.
- $min_values : int|null
- Minimum number of options that must be selected.
- $options : array<string|int, mixed>|null
- Specified choices in a select menu (only required and available for string selects (type 3); max 25.
- $placeholder : string|null
- Placeholder string to display if nothing is selected. Maximum 150 characters.
- $required : bool|null
- Whether the select menu is required. Defaults to true. (Modal only).
- $type : int
- Component type.
Methods
- __construct() : mixed
- Creates a new select menu.
- getChannelTypes() : array<string|int, mixed>|null
- Returns the channel types of the select menu.
- getCustomId() : string
- Returns the Custom ID of the select menu.
- getDefaultValues() : array<string|int, mixed>|null
- Returns the default values of the select menu.
- getMaxValues() : int|null
- Returns the maximum number of options that must be selected.
- getMinValues() : int|null
- Returns the minimum number of options that must be selected.
- getOptions() : array<string|int, mixed>|null
- Returns the options of the select menu.
- getPlaceholder() : string|null
- Returns the placeholder string of the select menu.
- getType() : int
- Retrieves the type of the component.
- isDisabled() : bool|null
- Returns whether the select menu is disabled.
- jsonSerialize() : array<string|int, mixed>
- new() : static
- Creates a new select menu.
- removeListener() : $this
- Removes the listener from the button.
- setChannelTypes() : $this
- Sets the channel types for the select menu.
- setCustomId() : $this
- Sets the custom ID for the select menu.
- setDefaultValues() : self
- setDisabled() : $this
- Sets the select menus disabled state. (Message only).
- setListener() : $this
- Sets the callable listener for the select menu. The `$callback` function will be called when the selection of the menu is changed.
- setMaxValues() : $this
- Sets the maximum number of options which must be chosen.
- setMinValues() : $this
- Sets the minimum number of options which must be chosen.
- setOptions() : $this
- Specified choices in a select menu (only required and available for string selects (type 3); max 25.
- setPlaceholder() : $this
- Sets the placeholder string to display if nothing is selected.
- setType() : string
- Sets the type for the select menu.
- createListener() : callable
- Creates a listener callback for handling select menu interactions.
- generateUuid() : string
- Generates a UUID which can be used for component custom IDs.
- getId() : int|null
- Retrieves the ID associated with the interactive component.
- setId() : self
- The id field is optional and is used to identify components in the response from an interaction. The id must be unique within the message and is generated sequentially if left empty. Generation of ids won't use another id that exists in the message if you have one defined for another component. Sending components with an id of 0 is allowed but will be treated as empty and replaced by the API. 32 bit integer used as an optional identifier for component.
Constants
TYPE_ACTION_ROW
public
mixed
TYPE_ACTION_ROW
= 1
TYPE_BUTTON
public
mixed
TYPE_BUTTON
= 2
TYPE_CHANNEL_SELECT
public
mixed
TYPE_CHANNEL_SELECT
= 8
TYPE_CONTAINER
public
mixed
TYPE_CONTAINER
= 17
TYPE_CONTENT_INVENTORY_ENTRY
public
mixed
TYPE_CONTENT_INVENTORY_ENTRY
= 16
TYPE_FILE
public
mixed
TYPE_FILE
= 13
TYPE_LABEL
public
mixed
TYPE_LABEL
= 18
TYPE_MEDIA_GALLERY
public
mixed
TYPE_MEDIA_GALLERY
= 12
TYPE_MENTIONABLE_SELECT
public
mixed
TYPE_MENTIONABLE_SELECT
= 7
TYPE_ROLE_SELECT
public
mixed
TYPE_ROLE_SELECT
= 6
TYPE_SECTION
public
mixed
TYPE_SECTION
= 9
TYPE_SELECT_MENU
Use Component::TYPE_STRING_SELECT
public
mixed
TYPE_SELECT_MENU
= 3
TYPE_SEPARATOR
public
mixed
TYPE_SEPARATOR
= 14
TYPE_STRING_SELECT
public
mixed
TYPE_STRING_SELECT
= 3
TYPE_TEXT_DISPLAY
public
mixed
TYPE_TEXT_DISPLAY
= 10
TYPE_TEXT_INPUT
public
mixed
TYPE_TEXT_INPUT
= 4
TYPE_THUMBNAIL
public
mixed
TYPE_THUMBNAIL
= 11
TYPE_USER_SELECT
public
mixed
TYPE_USER_SELECT
= 5
USAGE
public
mixed
USAGE
= ['Message', 'Modal']
Properties
$channel_types
List of channel types to include in the channel select component (type 8).
protected
array<string|int, mixed>|null
$channel_types
$custom_id
Custom ID to identify the select menu.
protected
string
$custom_id
$default_values
List of default values for auto-populated select menu components; number of default values must be in the range defined by min_values and max_values.
protected
array<string|int, mixed>|null
$default_values
$disabled
Whether the select menu should be disabled.
protected
bool|null
$disabled
$discord
Discord instance when the listener is set.
protected
Discord|null
$discord
$id
32 bit integer used as an optional identifier for component.
protected
int|null
$id
$listener
Callback used to listen for `INTERACTION_CREATE` events.
protected
callable|null
$listener
$max_values
Maximum number of options that must be selected.
protected
int|null
$max_values
Default 1, maximum 25.
$min_values
Minimum number of options that must be selected.
protected
int|null
$min_values
Default 1, minimum 0, maximum 25.
$options
Specified choices in a select menu (only required and available for string selects (type 3); max 25.
protected
array<string|int, mixed>|null
$options
$placeholder
Placeholder string to display if nothing is selected. Maximum 150 characters.
protected
string|null
$placeholder
$required
Whether the select menu is required. Defaults to true. (Modal only).
protected
bool|null
$required
$type
Component type.
protected
int
$type
= \Discord\Builders\Components\Component::TYPE_SELECT_MENU
Methods
__construct()
Creates a new select menu.
public
__construct(string|null $custom_id) : mixed
Parameters
- $custom_id : string|null
-
The custom ID of the select menu. If not given, a UUID will be used
getChannelTypes()
Returns the channel types of the select menu.
public
getChannelTypes() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetCustomId()
Returns the Custom ID of the select menu.
public
getCustomId() : string
Return values
stringgetDefaultValues()
Returns the default values of the select menu.
public
getDefaultValues() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetMaxValues()
Returns the maximum number of options that must be selected.
public
getMaxValues() : int|null
Return values
int|nullgetMinValues()
Returns the minimum number of options that must be selected.
public
getMinValues() : int|null
Return values
int|nullgetOptions()
Returns the options of the select menu.
public
getOptions() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetPlaceholder()
Returns the placeholder string of the select menu.
public
getPlaceholder() : string|null
Return values
string|nullgetType()
Retrieves the type of the component.
public
getType() : int
Return values
intisDisabled()
Returns whether the select menu is disabled.
public
isDisabled() : bool|null
Return values
bool|nulljsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>new()
Creates a new select menu.
public
static new([string|null $custom_id = null ]) : static
Parameters
- $custom_id : string|null = null
-
The custom ID of the select menu.
Return values
staticremoveListener()
Removes the listener from the button.
public
removeListener() : $this
Return values
$thissetChannelTypes()
Sets the channel types for the select menu.
public
setChannelTypes(array<string|int, mixed> $channel_types) : $this
This method is only applicable if the select menu type is TYPE_CHANNEL_SELECT
.
If the select menu type is not TYPE_CHANNEL_SELECT
, an InvalidArgumentException
will be thrown.
Parameters
- $channel_types : array<string|int, mixed>
Tags
Return values
$thissetCustomId()
Sets the custom ID for the select menu.
public
setCustomId(string $custom_id) : $this
Parameters
- $custom_id : string
Tags
Return values
$thissetDefaultValues()
public
setDefaultValues(array<string|int, mixed>|null $default_values) : self
Parameters
- $default_values : array<string|int, mixed>|null
Return values
selfsetDisabled()
Sets the select menus disabled state. (Message only).
public
setDisabled([bool|null $disabled = true ]) : $this
Parameters
- $disabled : bool|null = true
Return values
$thissetListener()
Sets the callable listener for the select menu. The `$callback` function will be called when the selection of the menu is changed.
public
setListener(callable $callback, Discord $discord[, bool $oneOff = false ][, int|float|null $timeout = null ]) : $this
The callback function is called with the Interaction
object as well as
a Collection
of selected options.
If you do not respond to or acknowledge the Interaction
, it will be
acknowledged for you.
Note that if you intend to respond to or acknowledge the interaction
inside a promise, you should return a promise that resolves after you
respond or acknowledge.
The callback will only be called once with the $oneOff
parameter set to
true.
This can be changed to false, and the callback will be called each time
the selection is changed. To remove the listener, you can pass
$callback
as null.
The select menu listener will not persist when the bot restarts.
Parameters
- $callback : callable
-
Callback to call when the selection is changed. Will be called with the interaction object and collection of options.
- $discord : Discord
-
Discord client.
- $oneOff : bool = false
-
Whether the listener should be removed after the selection is changed for the first time.
- $timeout : int|float|null = null
Tags
Return values
$thissetMaxValues()
Sets the maximum number of options which must be chosen.
public
setMaxValues(int|null $max_values) : $this
Parameters
- $max_values : int|null
-
Default
1
and maximum25
.null
to set as default.
Tags
Return values
$thissetMinValues()
Sets the minimum number of options which must be chosen.
public
setMinValues(int|null $min_values) : $this
Parameters
- $min_values : int|null
-
Default
1
, minimum0
and maximum25
.null
to set as default.
Tags
Return values
$thissetOptions()
Specified choices in a select menu (only required and available for string selects (type 3); max 25.
public
setOptions(array<string|int, mixed> $options) : $this
Parameters
- $options : array<string|int, mixed>
Tags
Return values
$thissetPlaceholder()
Sets the placeholder string to display if nothing is selected.
public
setPlaceholder(string|null $placeholder) : $this
Parameters
- $placeholder : string|null
-
Maximum 150 characters.
null
to clear placeholder.
Tags
Return values
$thissetType()
Sets the type for the select menu.
public
setType(int $type) : string
(text: 3, user: 5, role: 6, mentionable: 7, channels: 8).
Parameters
- $type : int
Tags
Return values
stringcreateListener()
Creates a listener callback for handling select menu interactions.
protected
createListener(callable $callback[, bool $oneOff = false ][, int|float|null $timeout = null ]) : callable
Parameters
- $callback : callable
-
The callback to execute when the interaction is received. If the select menu has options, the callback receives ($interaction, $options), otherwise just ($interaction).
- $oneOff : bool = false
-
Whether the listener should be removed after being triggered once.
- $timeout : int|float|null = null
-
Optional timeout in seconds after which the listener will be removed.
Return values
callable —The listener closure to be registered for interaction events.
generateUuid()
Generates a UUID which can be used for component custom IDs.
protected
static generateUuid() : string
Return values
stringgetId()
Retrieves the ID associated with the interactive component.
protected
getId() : int|null
Always returns null as this component does not have an ID.
Return values
int|nullsetId()
The id field is optional and is used to identify components in the response from an interaction. The id must be unique within the message and is generated sequentially if left empty. Generation of ids won't use another id that exists in the message if you have one defined for another component. Sending components with an id of 0 is allowed but will be treated as empty and replaced by the API. 32 bit integer used as an optional identifier for component.
protected
setId([string|null $id = null ]) : self
Parameters
- $id : string|null = null
-
32 bit integer used as an optional identifier for component.