Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ it will either be refactored, or redone.

## Contributing

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

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

Expand Down
15 changes: 5 additions & 10 deletions docs/interactions/ui-components/buttons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,12 @@ class MyView(discord.ui.View):
class MyView(discord.ui.View):
@discord.ui.button(emoji="😀", label="Button 1", style=discord.ButtonStyle.primary)
async def button_callback(self, button, interaction):
for child in self.children: # loop through all the children of the view
child.disabled = True # set the button to disabled
self.disable_all_items()
await interaction.response.edit_message(view=self)

@discord.ui.button(label="Button 2", style=discord.ButtonStyle.primary)
async def second_button_callback(self, button, interaction):
for child in self.children:
child.disabled = True
self.disable_all_items()
await interaction.response.edit_message(view=self)
```

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

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

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

@discord.ui.button()
Expand All @@ -234,8 +230,7 @@ class MyView(discord.ui.View):
</TabItem>
</Tabs>

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

:::note

Expand Down
35 changes: 15 additions & 20 deletions docs/interactions/ui-components/dropdowns.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ These UI elements reside in a "view". To learn more about views, please refer to

## Usage Syntax

Let's see how to create a simple responsive button.
Let's see how to create a simple responsive select menu.

```python
import discord
Expand Down Expand Up @@ -173,28 +173,28 @@ class MyView(discord.ui.View):
```python
class MyView(discord.ui.View):
@discord.ui.select(
disabled = True, # pass disabled=True to set the button as disabled
disabled = True, # pass disabled=True to set the menu as disabled
options = [...]
)
async def select_callback(self, select, interaction):
...

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

### Disabling Buttons on Press
### Disabling Menus on Press

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

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

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

@discord.ui.select(options = [...])
async def second_select_callback(self, select, interaction):
for child in self.children:
child.disabled = True
self.disable_all_items()
await interaction.response.edit_message(view=self)
```

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

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

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

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

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

:::note

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

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

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.

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

@bot.command()
async def button(ctx):
async def select_menu(ctx):
await ctx.send(f"View persistence status: {MyView.is_persistent(MyView())}", view=MyView())
```

Expand Down