Skip to content

Commit cc0dba6

Browse files
authored
docs: Document select types and select channel types (#317)
* docs: Document select types and select channel types * fix: Remove inaccurate info about select.values * feat: Add shortcut decorators for select menus * fix: Update code to use `.mention` on select.values[0] instead of using a raw mention
1 parent 27dc12f commit cc0dba6

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

docs/interactions/ui-components/dropdowns.mdx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ about making your code do amazing things, while Pycord handles the rest!
8181

8282
#### Select Menu Properties
8383

84-
- `options`\*: A list of [`discord.SelectOption`](https://docs.pycord.dev/en/stable/api/data_classes.html#discord.SelectOption) values. These are the options that can be selected in this menu.
84+
- `select_type`: The type of select to create. This must be a [`discord.ComponentType`](https://docs.pycord.dev/en/stable/api/enums.html#discord.ComponentType) value.
85+
- `channel_types`: A list of channel types that can be selected in the menu. This is only valid for selects of `select_type` [`discord.ComponentType.channel_select`](https://docs.pycord.dev/en/stable/api/enums.html#discord.ComponentType).
86+
- `options`: A list of [`discord.SelectOption`](https://docs.pycord.dev/en/stable/api/data_classes.html#discord.SelectOption) values. These are the options that can be selected in this menu.
8587
- `placeholder` is the placeholder text shown in the select menu if no option is selected.
8688
- `custom_id`: The ID of the select menu that gets received during an interaction. It is recommended not to set this to anything unless you are trying to create a persistent view.
8789
- `row`: The relative row this select menu belongs to. A Discord component can only have 5 rows. By default, items are arranged automatically into those 5 rows. If you’d like to control the relative positioning of the row then passing an index is advised. For example, row=1 will show up before row=2. Defaults to None, which is automatic ordering. The row number must be between 0 and 4 (i.e. zero indexed).
8890
- `min_values`: The minimum number of items that must be chosen for this select menu. Defaults to 1 and must be between 1 and 25.
8991
- `max_values`: The maximum number of items that must be chosen for this select menu. Defaults to 1 and must be between 1 and 25.
9092
- `disabled`: Whether the select is disabled or not. Defaults to False.
9193

92-
\* means that the parameter is required.
93-
9494
#### Select Option Properties
9595

9696
In the `options` parameter, you pass a list of [`discord.SelectOption`](https://docs.pycord.dev/en/stable/api/data_classes.html#discord.SelectOption) values. This class also has a few parameters:
@@ -100,6 +100,42 @@ In the `options` parameter, you pass a list of [`discord.SelectOption`](https://
100100
- `label` (the name displayed to users, can be up to 100 characters)
101101
- `value` (a special value of the option, defaults to the label).
102102

103+
## Select Types
104+
105+
In addition to regular string selects, you can also have your select menu contain users, roles, mentionables, and channels as its options. You can use these alternative select types by passing a [`discord.ComponentType`](https://docs.pycord.dev/en/stable/api/enums.html#discord.ComponentType) value for the `select_type` parameter when creating the Select.
106+
107+
```python
108+
class MyView(discord.ui.View):
109+
@discord.ui.select(
110+
select_type=discord.ComponentType.user_select
111+
)
112+
async def select_callback(self, select, interaction):
113+
await interaction.response.send_message(f"Hello, {select.values[0].mention}")
114+
```
115+
116+
Additionally, you can use shortcut decorators to create a [`discord.ui.Select`](https://docs.pycord.dev/en/master/api/ui_kit.html#discord.ui.select) with a predetermined [`discord.ComponentType`](https://docs.pycord.dev/en/stable/api/enums.html#discord.ComponentType) value. Using a shortcut decorator, the above code can be rewritten like this:
117+
118+
```python
119+
class MyView(discord.ui.View):
120+
@discord.ui.user_select()
121+
async def select_callback(self, select, interaction):
122+
await interaction.response.send_message(f"Hello, {select.values[0].mention}")
123+
```
124+
125+
### Specifying Channel Types
126+
127+
When using a [`discord.ComponentType.channel_select`](https://docs.pycord.dev/en/stable/api/enums.html#discord.ComponentType.channel_select) type select menu, you can pass in a list of [`discord.ChannelType`](https://docs.pycord.dev/en/stable/api/enums.html#discord.ChannelType) values to limit which types of channels users can choose when interacting with the select menu.
128+
129+
```python
130+
class MyView(discord.ui.View):
131+
@discord.ui.select(
132+
select_type=discord.ComponentType.channel_select,
133+
channel_types=[discord.ChannelType.text, discord.ChannelType.voice]
134+
)
135+
async def select_callback(self, select, interaction):
136+
await interaction.response.send_message(f"You selected {select.values[0].mention}")
137+
```
138+
103139
## Action Rows
104140
105141
We have discussed that Views can have 5 rows. Each row has 5 slots. A button takes a single slot, while a select menu takes up all 5 of them. This means a view can have a maximum of 5 select menus, or any possible combination of select menus and buttons.

0 commit comments

Comments
 (0)