Skip to content

Commit 9976076

Browse files
committed
Merge branch 'main' into production
2 parents e600b8b + 5872d70 commit 9976076

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ it will either be refactored, or redone.
1111

1212
## Contributing
1313

14-
For contributing rules, please visit [this page](./.github/CONTRIBUTING.md).
14+
For contributing rules, please visit [this page](./CONTRIBUTING.md).
1515

1616
The Guide is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
1717

docs/interactions/ui-components/buttons.mdx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,12 @@ class MyView(discord.ui.View):
176176
class MyView(discord.ui.View):
177177
@discord.ui.button(emoji="😀", label="Button 1", style=discord.ButtonStyle.primary)
178178
async def button_callback(self, button, interaction):
179-
for child in self.children: # loop through all the children of the view
180-
child.disabled = True # set the button to disabled
179+
self.disable_all_items()
181180
await interaction.response.edit_message(view=self)
182181

183182
@discord.ui.button(label="Button 2", style=discord.ButtonStyle.primary)
184183
async def second_button_callback(self, button, interaction):
185-
for child in self.children:
186-
child.disabled = True
184+
self.disable_all_items()
187185
await interaction.response.edit_message(view=self)
188186
```
189187

@@ -200,8 +198,7 @@ Sometimes, you want to have a button that is disabled after a certain amount of
200198
```python
201199
class MyView(discord.ui.View):
202200
async def on_timeout(self):
203-
for child in self.children:
204-
child.disabled = True
201+
self.disable_all_items()
205202
await self.message.edit(content="You took too long! Disabled all the components.", view=self)
206203

207204
@discord.ui.button()
@@ -222,8 +219,7 @@ class MyView(discord.ui.View):
222219
super().__init__(timeout=10) # specify the timeout here
223220

224221
async def on_timeout(self):
225-
for child in self.children:
226-
child.disabled = True
222+
self.disable_all_items()
227223
await self.message.edit(content="You took too long! Disabled all the components.", view=self)
228224

229225
@discord.ui.button()
@@ -234,8 +230,7 @@ class MyView(discord.ui.View):
234230
</TabItem>
235231
</Tabs>
236232

237-
Here, we loop through all the children of the view (buttons and select menus in the view) and disable
238-
them. Then, we edit the message to show that the timeout was reached.
233+
Here, we disable all buttons and select menus in the view. Then, we edit the message to show that the timeout was reached.
239234

240235
:::note
241236

docs/interactions/ui-components/dropdowns.mdx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ These UI elements reside in a "view". To learn more about views, please refer to
1919

2020
## Usage Syntax
2121

22-
Let's see how to create a simple responsive button.
22+
Let's see how to create a simple responsive select menu.
2323

2424
```python
2525
import discord
@@ -173,28 +173,28 @@ class MyView(discord.ui.View):
173173
```python
174174
class MyView(discord.ui.View):
175175
@discord.ui.select(
176-
disabled = True, # pass disabled=True to set the button as disabled
176+
disabled = True, # pass disabled=True to set the menu as disabled
177177
options = [...]
178178
)
179179
async def select_callback(self, select, interaction):
180180
...
181181

182182
@bot.command()
183-
async def button(ctx):
184-
await ctx.send("Press the button!", view=MyView())
183+
async def select_menu(ctx):
184+
await ctx.send("Select and option from the menu!", view=MyView())
185185
```
186186

187-
### Disabling Buttons on Press
187+
### Disabling Menus on Press
188188

189189
<Tabs>
190190
<TabItem value="disabling-a-single-component" label="Disabling a single component" default>
191191

192192
```python
193193
class MyView(discord.ui.View):
194194
@discord.ui.select(options = [...])
195-
async def select_callback(self, select, interaction):
196-
select.disabled = True # set the status of the select as disabled
197-
await interaction.response.edit_message(view=self) # edit the message to show the changes
195+
async def select_callback(self, select, interaction):
196+
select.disabled = True # set the status of the select as disabled
197+
await interaction.response.edit_message(view=self) # edit the message to show the changes
198198
```
199199

200200
</TabItem>
@@ -205,14 +205,12 @@ class MyView(discord.ui.View):
205205
class MyView(discord.ui.View):
206206
@discord.ui.select(options = [...])
207207
async def first_select_callback(self, select, interaction):
208-
for child in self.children: # loop through all the children of the view
209-
child.disabled = True # set the component to disabled
208+
self.disable_all_items()
210209
await interaction.response.edit_message(view=self) # edit the message to show the changes
211210

212211
@discord.ui.select(options = [...])
213212
async def second_select_callback(self, select, interaction):
214-
for child in self.children:
215-
child.disabled = True
213+
self.disable_all_items()
216214
await interaction.response.edit_message(view=self)
217215
```
218216

@@ -229,8 +227,7 @@ You may want a select menu to automatically stop working after a certain amount
229227
```python
230228
class MyView(discord.ui.View):
231229
async def on_timeout(self):
232-
for child in self.children:
233-
child.disabled = True
230+
self.disable_all_items()
234231
await self.message.edit(content="You took too long! Disabled all the components.", view=self)
235232

236233
@discord.ui.select(options = [...])
@@ -251,8 +248,7 @@ class MyView(discord.ui.View):
251248
super().__init__(timeout=10) # specify the timeout here
252249

253250
async def on_timeout(self):
254-
for child in self.children:
255-
child.disabled = True
251+
self.disable_all_items()
256252
await self.message.edit(content="You took too long! Disabled all the components.", view=self)
257253

258254
@discord.ui.select(options = [...])
@@ -263,8 +259,7 @@ class MyView(discord.ui.View):
263259
</TabItem>
264260
</Tabs>
265261

266-
Here, we loop through all the children of the view (buttons and select menus in the view) and disable
267-
them. Then, we edit the message to show that the timeout was reached.
262+
Here, we disable all buttons and select menus in the view. Then, we edit the message to show that the timeout was reached.
268263

269264
:::note
270265

@@ -281,7 +276,7 @@ Normally, when the bot goes offline, all of its views stop working, even if they
281276
views, but nothing will happen when you try to interact with them. This is a problem
282277
if you are trying to create a self-role system, for example. This is where persistent views come in.
283278

284-
Persistent views work forever. When the bot goes offline, the buttons will stop working. However, when the bot comes back online, the buttons will start working again.
279+
Persistent views work forever. When the bot goes offline, the buttons and select menus will stop working. However, when the bot comes back online, the buttons and select menus will start working again.
285280

286281
In a Persistent View, the timeout must be set to `None` and all the children in the view much have a `custom_id` attribute set.
287282

@@ -299,7 +294,7 @@ class MyView(discord.ui.View):
299294
...
300295

301296
@bot.command()
302-
async def button(ctx):
297+
async def select_menu(ctx):
303298
await ctx.send(f"View persistence status: {MyView.is_persistent(MyView())}", view=MyView())
304299
```
305300

0 commit comments

Comments
 (0)