From 4f2034e7459bfc9cf5545d4cf9473d875e6b68c7 Mon Sep 17 00:00:00 2001 From: NeloBlivion <41271523+NeloBlivion@users.noreply.github.com> Date: Sat, 1 Oct 2022 04:02:43 +0100 Subject: [PATCH 1/3] Add get_item to View --- discord/ui/view.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/discord/ui/view.py b/discord/ui/view.py index a0413b2eb4..893b1a56fb 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -52,6 +52,7 @@ from ..components import SelectMenu as SelectComponent from ..components import _component_factory from .item import Item, ItemCallbackType +from ..utils import get __all__ = ("View",) @@ -312,6 +313,21 @@ def clear_items(self) -> None: self.children.clear() self.__weights.clear() + def get_item(self, custom_id: str) -> Optional[Item]: + """Get an item from the view by its ``custom_id``. + + Parameters + ----------- + custom_id: :class:`str` + The custom_id of the item to get + + Returns + -------- + Optional[:class:`Item`] + The item with the matching ``custom_id`` if it exists. + """ + return get(self.children, custom_id=custom_id) + async def interaction_check(self, interaction: Interaction) -> bool: """|coro| From f3cc48ae082e50d7785b72f978a66f56ceaa2fd6 Mon Sep 17 00:00:00 2001 From: NeloBlivion <41271523+NeloBlivion@users.noreply.github.com> Date: Sat, 1 Oct 2022 04:43:00 +0100 Subject: [PATCH 2/3] Update discord/ui/view.py Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com> --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 893b1a56fb..1529a26e10 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -314,7 +314,7 @@ def clear_items(self) -> None: self.__weights.clear() def get_item(self, custom_id: str) -> Optional[Item]: - """Get an item from the view by its ``custom_id``. + """Get an item from the view by its ``custom_id``. Alias for `utils.get(view.children, custom_id=custom_id)`. Parameters ----------- From 825db85c11b9cef595ce1bf0123050eeb0d4df12 Mon Sep 17 00:00:00 2001 From: NeloBlivion <41271523+NeloBlivion@users.noreply.github.com> Date: Sat, 1 Oct 2022 13:03:13 +0100 Subject: [PATCH 3/3] Updated wording to match other get functions --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 1529a26e10..a3461259c5 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -314,7 +314,7 @@ def clear_items(self) -> None: self.__weights.clear() def get_item(self, custom_id: str) -> Optional[Item]: - """Get an item from the view by its ``custom_id``. Alias for `utils.get(view.children, custom_id=custom_id)`. + """Get an item from the view with the given custom ID. Alias for `utils.get(view.children, custom_id=custom_id)`. Parameters -----------