DiscordPHP Documentation

SelectMenu extends Component
in package

Select menus are interactive components that allow users to select one or more options from a dropdown list in messages.

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
link
https://discord.com/developers/docs/interactions/message-components#select-menus
since
10.0.0

Renamed from SelectMenu to StringSelect and made SelectMenu abstract

Table of Contents

TYPE_ACTION_ROW  = 1
TYPE_BUTTON  = 2
TYPE_CHANNEL_SELECT  = 8
TYPE_MENTIONABLE_SELECT  = 7
TYPE_ROLE_SELECT  = 6
TYPE_SELECT_MENU  = 3
TYPE_STRING_SELECT  = 3
TYPE_TEXT_INPUT  = 4
TYPE_USER_SELECT  = 5
$custom_id  : string
Custom ID to identify the select menu.
$disabled  : bool|null
Whether the select menu should be disabled.
$discord  : Discord|null
Discord instance when the listener is set.
$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.
$placeholder  : string|null
Placeholder string to display if nothing is selected. Maximum 150 characters.
__construct()  : mixed
Creates a new select menu.
getCustomId()  : string
Returns the Custom ID 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.
getPlaceholder()  : string|null
Returns the placeholder string of the select menu.
isDisabled()  : bool|null
Returns wether the select menu is disabled.
jsonSerialize()  : array<string|int, mixed>
{@inheritDoc}
new()  : static
Creates a new select menu.
removeListener()  : $this
Removes the listener from the button.
setCustomId()  : $this
Sets the custom ID for the select menu.
setDisabled()  : $this
Sets the select menus disabled state.
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.
setPlaceholder()  : $this
Sets the placeholder string to display if nothing is selected.
generateUuid()  : string
Generates a UUID which can be used for component custom IDs.

Constants

TYPE_ACTION_ROW

public mixed TYPE_ACTION_ROW = 1

TYPE_CHANNEL_SELECT

public mixed TYPE_CHANNEL_SELECT = 8

TYPE_MENTIONABLE_SELECT

public mixed TYPE_MENTIONABLE_SELECT = 7

TYPE_ROLE_SELECT

public mixed TYPE_ROLE_SELECT = 6

TYPE_SELECT_MENU

public mixed TYPE_SELECT_MENU = 3
Tags
deprecated
7.4.0

Use Component::TYPE_STRING_SELECT

TYPE_STRING_SELECT

public mixed TYPE_STRING_SELECT = 3

TYPE_TEXT_INPUT

public mixed TYPE_TEXT_INPUT = 4

TYPE_USER_SELECT

public mixed TYPE_USER_SELECT = 5

Properties

$custom_id

Custom ID to identify the select menu.

protected string $custom_id

$disabled

Whether the select menu should be disabled.

protected bool|null $disabled

$discord

Discord instance when the listener is set.

protected Discord|null $discord

$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.

$placeholder

Placeholder string to display if nothing is selected. Maximum 150 characters.

protected string|null $placeholder

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, an UUID will be used

Return values
mixed

getCustomId()

Returns the Custom ID of the select menu.

public getCustomId() : string
Return values
string

getMaxValues()

Returns the maximum number of options that must be selected.

public getMaxValues() : int|null
Return values
int|null

getMinValues()

Returns the minimum number of options that must be selected.

public getMinValues() : int|null
Return values
int|null

getPlaceholder()

Returns the placeholder string of the select menu.

public getPlaceholder() : string|null
Return values
string|null

isDisabled()

Returns wether the select menu is disabled.

public isDisabled() : bool|null
Return values
bool|null

jsonSerialize()

{@inheritDoc}

public jsonSerialize() : array<string|int, mixed>
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
static

removeListener()

Removes the listener from the button.

public removeListener() : $this
Return values
$this

setCustomId()

Sets the custom ID for the select menu.

public setCustomId(string $custom_id) : $this
Parameters
$custom_id : string
Tags
throws
LengthException
Return values
$this

setDisabled()

Sets the select menus disabled state.

public setDisabled([bool $disabled = true ]) : $this
Parameters
$disabled : bool = true
Return values
$this

setListener()

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 ]) : $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.

Tags
todo

setListener callback return for each type.

Return values
$this

setMaxValues()

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 maximum 25. null to set as default.

Tags
throws
LengthException
Return values
$this

setMinValues()

Sets the minimum number of options which must be chosen.

public setMinValues(int|null $min_values) : $this
Parameters
$min_values : int|null

Default 1, minimum 0 and maximum 25. null to set as default.

Tags
throws
LengthException
Return values
$this

setPlaceholder()

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
throws
LengthException
Return values
$this

generateUuid()

Generates a UUID which can be used for component custom IDs.

protected static generateUuid() : string
Return values
string

Search results