diff --git a/README.md b/README.md index eda49a3c..00c4b109 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/interactions/ui-components/buttons.mdx b/docs/interactions/ui-components/buttons.mdx index 0c4a18e8..a901de9b 100644 --- a/docs/interactions/ui-components/buttons.mdx +++ b/docs/interactions/ui-components/buttons.mdx @@ -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) ``` @@ -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() @@ -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() @@ -234,8 +230,7 @@ class MyView(discord.ui.View): -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 diff --git a/docs/interactions/ui-components/dropdowns.mdx b/docs/interactions/ui-components/dropdowns.mdx index 7adb6e37..081cfad7 100644 --- a/docs/interactions/ui-components/dropdowns.mdx +++ b/docs/interactions/ui-components/dropdowns.mdx @@ -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 @@ -173,18 +173,18 @@ 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 @@ -192,9 +192,9 @@ async def button(ctx): ```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 ``` @@ -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) ``` @@ -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 = [...]) @@ -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 = [...]) @@ -263,8 +259,7 @@ class MyView(discord.ui.View): -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 @@ -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. @@ -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()) ```