Skip to content

Commit e8075e4

Browse files
GeomKidFayeDelpre-commit-ci[bot]Damego
authored
feat: add component property to ComponentContext (#1268)
* feat: add component to property of ComponentContext * ci: correct from checks. * feat: add check for message * refactor: simplify condition --------- Co-authored-by: DeltaX <33706469+DeltaXWizard@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Damego <damego.dev@gmail.com>
1 parent 2c3ffa3 commit e8075e4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

interactions/api/models/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,4 +1381,4 @@ async def disable_all_components(self) -> "Message":
13811381
payload={"components": [component._json for component in self.components]},
13821382
),
13831383
_client=self._client,
1384-
)
1384+
)

interactions/client/context.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,20 @@ def label(self) -> Optional[str]:
846846
for component in action_row.components:
847847
if component.custom_id == self.custom_id:
848848
return component.label
849+
850+
@property
851+
def component(self) -> Optional[Union[Button, SelectMenu]]:
852+
"""
853+
.. versionadded:: 4.4.0
854+
855+
The component that you interacted.
856+
857+
:rtype: Optional[Union[Button, SelectMenu]]
858+
"""
859+
if self.message is None or self.message.components is None:
860+
return
861+
862+
for action_row in self.message.components:
863+
for component in action_row.components:
864+
if component.custom_id == self.custom_id:
865+
return component

0 commit comments

Comments
 (0)