Skip to content

Commit 393749f

Browse files
Add View.get_item shortcut method (#1659)
* Add get_item to View * Update discord/ui/view.py Co-authored-by: BobDotCom <[email protected]> * Updated wording to match other get functions Co-authored-by: BobDotCom <[email protected]>
1 parent 87cb440 commit 393749f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

discord/ui/view.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from ..components import SelectMenu as SelectComponent
5353
from ..components import _component_factory
5454
from .item import Item, ItemCallbackType
55+
from ..utils import get
5556

5657
__all__ = ("View",)
5758

@@ -312,6 +313,21 @@ def clear_items(self) -> None:
312313
self.children.clear()
313314
self.__weights.clear()
314315

316+
def get_item(self, custom_id: str) -> Optional[Item]:
317+
"""Get an item from the view with the given custom ID. Alias for `utils.get(view.children, custom_id=custom_id)`.
318+
319+
Parameters
320+
-----------
321+
custom_id: :class:`str`
322+
The custom_id of the item to get
323+
324+
Returns
325+
--------
326+
Optional[:class:`Item`]
327+
The item with the matching ``custom_id`` if it exists.
328+
"""
329+
return get(self.children, custom_id=custom_id)
330+
315331
async def interaction_check(self, interaction: Interaction) -> bool:
316332
"""|coro|
317333

0 commit comments

Comments
 (0)