Browse Source

chore: Add get_item_by_id to remaining items

pull/10166/head
DA-344 2 months ago
parent
commit
86dd8d8b9a
  1. 22
      discord/ui/action_row.py
  2. 22
      discord/ui/container.py
  3. 22
      discord/ui/section.py

22
discord/ui/action_row.py

@ -47,7 +47,7 @@ from .select import select as _select, Select, UserSelect, RoleSelect, ChannelSe
from ..components import ActionRow as ActionRowComponent
from ..enums import ButtonStyle, ComponentType, ChannelType
from ..partial_emoji import PartialEmoji
from ..utils import MISSING
from ..utils import MISSING, get as _utils_get
if TYPE_CHECKING:
from typing_extensions import Self
@ -218,6 +218,26 @@ class ActionRow(Item[V]):
pass
return self
def get_item_by_id(self, id: str, /) -> Optional[Item[V]]:
"""Gets an item with :attr:`Item.id` set as ``id``, or ``None`` if
not found.
.. warning::
This is **not the same** as ``custom_id``.
Parameters
----------
id: :class:`str`
The ID of the component.
Returns
-------
Optional[:class:`Item`]
The item found, or ``None``.
"""
return _utils_get(self._children, id=id)
def clear_items(self) -> Self:
"""Removes all items from the row.

22
discord/ui/container.py

@ -29,7 +29,7 @@ from .item import Item, ItemCallbackType
from .view import _component_to_item, LayoutView
from .dynamic import DynamicItem
from ..enums import ComponentType
from ..utils import MISSING
from ..utils import MISSING, get as _utils_get
if TYPE_CHECKING:
from typing_extensions import Self
@ -287,6 +287,26 @@ class Container(Item[V]):
pass
return self
def get_item_by_id(self, id: str, /) -> Optional[Item[V]]:
"""Gets an item with :attr:`Item.id` set as ``id``, or ``None`` if
not found.
.. warning::
This is **not the same** as ``custom_id``.
Parameters
----------
id: :class:`str`
The ID of the component.
Returns
-------
Optional[:class:`Item`]
The item found, or ``None``.
"""
return _utils_get(self._children, id=id)
def clear_items(self) -> Self:
"""Removes all the items from the container.

22
discord/ui/section.py

@ -28,7 +28,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, TypeVar, U
from .item import Item
from .text_display import TextDisplay
from ..enums import ComponentType
from ..utils import MISSING
from ..utils import MISSING, get as _utils_get
if TYPE_CHECKING:
from typing_extensions import Self
@ -162,6 +162,26 @@ class Section(Item[V]):
pass
return self
def get_item_by_id(self, id: str, /) -> Optional[Item[V]]:
"""Gets an item with :attr:`Item.id` set as ``id``, or ``None`` if
not found.
.. warning::
This is **not the same** as ``custom_id``.
Parameters
----------
id: :class:`str`
The ID of the component.
Returns
-------
Optional[:class:`Item`]
The item found, or ``None``.
"""
return _utils_get(self._children, id=id)
def clear_items(self) -> Self:
"""Removes all the items from the section.

Loading…
Cancel
Save