Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add View.get_item shortcut method #1659

Merged
merged 4 commits into from
Oct 2, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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