DiscordPHP Documentation

UserSelect extends SelectMenu
in package

Select menu for users.

Tags
link
https://discord.com/developers/docs/interactions/message-components#select-menus
since
10.0.0

Table of Contents

Constants

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

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.
$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.
$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
Returns the type of the select menu.
isDisabled()  : bool|null
Returns whether 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.
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.
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.
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

Use Component::TYPE_STRING_SELECT

public mixed TYPE_SELECT_MENU = 3

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

$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

$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

$type

Component type.

protected int $type = \Discord\Builders\Components\Component::TYPE_USER_SELECT

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>|null

getCustomId()

Returns the Custom ID of the select menu.

public getCustomId() : string
Return values
string

getDefaultValues()

Returns the default values of the select menu.

public getDefaultValues() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

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

getOptions()

Returns the options of the select menu.

public getOptions() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

getPlaceholder()

Returns the placeholder string of the select menu.

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

getType()

Returns the type of the select menu.

public getType() : int
Return values
int

isDisabled()

Returns whether 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

setChannelTypes()

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
throws
InvalidArgumentException

If the select menu type is not TYPE_CHANNEL_SELECT.

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

If the custom ID is longer than 100 characters.

Return values
$this

setDefaultValues()

public setDefaultValues(array<string|int, mixed>|null $default_values) : self
Parameters
$default_values : array<string|int, mixed>|null
Return values
self

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

setOptions()

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
throws
InvalidArgumentException

If the select menu type is not TYPE_STRING_SELECT.

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

setType()

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
throws
InvalidArgumentException
Return values
string

generateUuid()

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

protected static generateUuid() : string
Return values
string

        
On this page

Search results