mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 09:26:10 +00:00
Add a swap method for dynamic item's dispatching
This commit is contained in:
@ -35,6 +35,7 @@ if TYPE_CHECKING:
|
||||
from typing_extensions import Self
|
||||
|
||||
from .view import LayoutView
|
||||
from .dynamic import DynamicItem
|
||||
from ..components import SectionComponent
|
||||
|
||||
V = TypeVar('V', bound='LayoutView', covariant=True)
|
||||
@ -117,6 +118,10 @@ class Section(Item[V]):
|
||||
def _is_v2(self) -> bool:
|
||||
return True
|
||||
|
||||
def _swap_item(self, base: Item, new: DynamicItem, custom_id: str) -> None:
|
||||
if self.accessory.is_dispatchable() and getattr(self.accessory, 'custom_id', None) == custom_id:
|
||||
self.accessory = new # type: ignore
|
||||
|
||||
def walk_children(self) -> Generator[Item[V], None, None]:
|
||||
"""An iterator that recursively walks through all the children of this section
|
||||
and its children, if applicable. This includes the `accessory`.
|
||||
|
Reference in New Issue
Block a user