From abe1cf91b8a7473c9bae25bc9d6c661d0fd7bfe3 Mon Sep 17 00:00:00 2001 From: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:01:30 +0530 Subject: [PATCH 1/7] Update buttons.mdx Update buttons page to use an inbuilt feature to disable all buttons rather than manually looping through all the children. Signed-off-by: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> --- docs/interactions/ui-components/buttons.mdx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 From 85d85a9f65ed593611407d3f7bfdf70fd9623f82 Mon Sep 17 00:00:00 2001 From: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:38:41 +0530 Subject: [PATCH 2/7] Update dropdowns.mdx Update Disabling code to use inbuilt functions rather than looping over all the children. Signed-off-by: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> --- docs/interactions/ui-components/dropdowns.mdx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/docs/interactions/ui-components/dropdowns.mdx b/docs/interactions/ui-components/dropdowns.mdx index 7adb6e37..c6b82a72 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 @@ -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 From 9560df4655191dc0651d4cdc4a5d40442813e37f Mon Sep 17 00:00:00 2001 From: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:46:13 +0530 Subject: [PATCH 3/7] Button mention in menus page changed Change few button mentions to select menus Signed-off-by: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> --- docs/interactions/ui-components/dropdowns.mdx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/interactions/ui-components/dropdowns.mdx b/docs/interactions/ui-components/dropdowns.mdx index c6b82a72..fd6fc944 100644 --- a/docs/interactions/ui-components/dropdowns.mdx +++ b/docs/interactions/ui-components/dropdowns.mdx @@ -181,10 +181,10 @@ class MyView(discord.ui.View): @bot.command() async def button(ctx): - await ctx.send("Press the button!", view=MyView()) + await ctx.send("Press thebutton!", view=MyView()) ``` -### Disabling Buttons on Press +### Disabling Menus on Press @@ -192,8 +192,7 @@ 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 + 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 ``` @@ -276,7 +275,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. @@ -294,7 +293,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()) ``` From a35da7f9406bf9a008e5be2d8716a18aca642156 Mon Sep 17 00:00:00 2001 From: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:49:16 +0530 Subject: [PATCH 4/7] Replacing few more button with menu mentions Signed-off-by: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> --- docs/interactions/ui-components/dropdowns.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/interactions/ui-components/dropdowns.mdx b/docs/interactions/ui-components/dropdowns.mdx index fd6fc944..d2994d7d 100644 --- a/docs/interactions/ui-components/dropdowns.mdx +++ b/docs/interactions/ui-components/dropdowns.mdx @@ -173,14 +173,14 @@ 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): +async def select_menu(ctx): await ctx.send("Press thebutton!", view=MyView()) ``` From 18d4e33ed50ac1e22adf2f61333559ae8f1eb786 Mon Sep 17 00:00:00 2001 From: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:50:45 +0530 Subject: [PATCH 5/7] Update dropdowns.mdx Signed-off-by: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> --- docs/interactions/ui-components/dropdowns.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/interactions/ui-components/dropdowns.mdx b/docs/interactions/ui-components/dropdowns.mdx index d2994d7d..915c2808 100644 --- a/docs/interactions/ui-components/dropdowns.mdx +++ b/docs/interactions/ui-components/dropdowns.mdx @@ -181,7 +181,7 @@ class MyView(discord.ui.View): @bot.command() async def select_menu(ctx): - await ctx.send("Press thebutton!", view=MyView()) + await ctx.send("Select and option from the menu!", view=MyView()) ``` ### Disabling Menus on Press From 023289052b944855e3eecb508fc9951e4c0c7540 Mon Sep 17 00:00:00 2001 From: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:58:09 +0530 Subject: [PATCH 6/7] Fix link in README Signed-off-by: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 08ab13e92b050ec2399b85c3df4460bc66959991 Mon Sep 17 00:00:00 2001 From: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> Date: Thu, 1 Jun 2023 16:09:37 +0530 Subject: [PATCH 7/7] Fix indents Signed-off-by: Ankit_Anmol <87054411+Quantum-Codes@users.noreply.github.com> --- docs/interactions/ui-components/dropdowns.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/interactions/ui-components/dropdowns.mdx b/docs/interactions/ui-components/dropdowns.mdx index 915c2808..081cfad7 100644 --- a/docs/interactions/ui-components/dropdowns.mdx +++ b/docs/interactions/ui-components/dropdowns.mdx @@ -192,8 +192,9 @@ async def select_menu(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 ```