From 10d1f11402ea2a68bbd6227a27e11ef7596f05bc Mon Sep 17 00:00:00 2001 From: GeomKid <51281740+GeomKid@users.noreply.github.com> Date: Sat, 4 Feb 2023 02:31:51 +0800 Subject: [PATCH 1/4] feat: add component to property of ComponentContext --- interactions/client/context.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/interactions/client/context.py b/interactions/client/context.py index e4260de61..2c2f6e0d6 100644 --- a/interactions/client/context.py +++ b/interactions/client/context.py @@ -846,3 +846,19 @@ def label(self) -> Optional[str]: for component in action_row.components: if component.custom_id == self.custom_id: return component.label + + @property + def component(self) -> Optional[Union[Button, SelectMenu]]: + """ + .. versionadded:: 4.4.0 + + The component that you interacted. + + :rtype: Optional[Union[Button, SelectMenu]] + """ + if self.message.components is None: + return + for action_row in self.message.components: + for component in action_row.components: + if component.custom_id == self.custom_id: + return component From 28fa4e4ae90fd47117878a925323f8bc102cce7b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 Feb 2023 18:33:52 +0000 Subject: [PATCH 2/4] ci: correct from checks. --- interactions/api/models/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/api/models/message.py b/interactions/api/models/message.py index 58dfc2e93..98873a883 100644 --- a/interactions/api/models/message.py +++ b/interactions/api/models/message.py @@ -1381,4 +1381,4 @@ async def disable_all_components(self) -> "Message": payload={"components": [component._json for component in self.components]}, ), _client=self._client, - ) \ No newline at end of file + ) From 5626e5894563d0e42fadbe2507a2c9bfb43db557 Mon Sep 17 00:00:00 2001 From: GeomKid <51281740+GeomKid@users.noreply.github.com> Date: Sat, 4 Feb 2023 02:40:33 +0800 Subject: [PATCH 3/4] feat: add check for message --- interactions/client/context.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interactions/client/context.py b/interactions/client/context.py index 2c2f6e0d6..841ffe12e 100644 --- a/interactions/client/context.py +++ b/interactions/client/context.py @@ -856,6 +856,8 @@ def component(self) -> Optional[Union[Button, SelectMenu]]: :rtype: Optional[Union[Button, SelectMenu]] """ + if self.message is None: + return if self.message.components is None: return for action_row in self.message.components: From 59f359005422f85bcf7db374e4aad8066c946755 Mon Sep 17 00:00:00 2001 From: Damego Date: Sat, 4 Feb 2023 09:24:56 +0500 Subject: [PATCH 4/4] refactor: simplify condition --- interactions/client/context.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/interactions/client/context.py b/interactions/client/context.py index 841ffe12e..182fbf05c 100644 --- a/interactions/client/context.py +++ b/interactions/client/context.py @@ -856,10 +856,9 @@ def component(self) -> Optional[Union[Button, SelectMenu]]: :rtype: Optional[Union[Button, SelectMenu]] """ - if self.message is None: - return - if self.message.components is None: + if self.message is None or self.message.components is None: return + for action_row in self.message.components: for component in action_row.components: if component.custom_id == self.custom_id: