Skip to content

Commit

Permalink
Add View.get_item shortcut method (#1659)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
NeloBlivion and BobDotCom authored Oct 2, 2022
1 parent 87cb440 commit 393749f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions discord/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)

Expand Down Expand Up @@ -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 with the given custom ID. Alias for `utils.get(view.children, custom_id=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|
Expand Down

0 comments on commit 393749f

Please sign in to comment.