@@ -109,43 +109,53 @@ def from_payload(cls, payload: P, state: ConnectionState | None = None) -> Self:
109109 ...
110110
111111
112- class WalkableComponent ( Component [ P ], ABC , Generic [P , C ]):
112+ class WalkableComponentMixin ( ABC , Generic [C ]):
113113 """A component that can be walked through.
114114
115115 This is an abstract class and cannot be instantiated directly.
116116 It is used to represent components that can be walked through, such as :class:`ActionRow`, :class:`Container` and :class:`Section`.
117117 """
118118
119- __slots__ : tuple [str , ...] = ("components" ,) # pyright: ignore[reportIncompatibleUnannotatedOverride]
120- components : list [C ]
121-
122- def walk_components (self ) -> Iterator [C ]:
123- """Walks through the components in this component."""
124- for component in self .components :
125- if isinstance (component , WalkableComponent ):
126- yield from component .walk_components ()
127- else :
128- yield component
119+ @abstractmethod
120+ def walk_components (self ) -> Iterator [C ]: ...
129121
130122 __iter__ : Callable [[Self ], Iterator [C ]] = walk_components
131123
132- @override
124+ @abstractmethod
125+ def is_v2 (self ) -> bool : ...
126+
127+ @abstractmethod
128+ def is_dispatchable (self ) -> bool : ...
129+
133130 def any_is_v2 (self ) -> bool :
134131 """Whether this component or any of its children were introduced in Components V2."""
135132 return self .is_v2 () or any (c .any_is_v2 () for c in self .walk_components ())
136133
137- @override
138134 def any_is_dispatchable (self ) -> bool :
139135 """Whether this component or any of its children can be interacted with and lead to a :class:`Interaction`"""
140136 return self .is_dispatchable () or any (c .any_is_dispatchable () for c in self .walk_components ())
141137
142138 def get_by_id (self , component_id : str | int ) -> C | None :
139+ """Gets a component by its ID or custom ID.
140+
141+ Parameters
142+ ----------
143+ component_id:
144+ The ID (int) or custom ID (str) of the component to get.
145+
146+ Returns
147+ -------
148+ :class:`AllowedComponents` | :class:`None`
149+ The children component with the given ID or custom ID, or :data:`None` if not found.
150+ """
143151 for component in self .walk_components ():
144152 if isinstance (component_id , str ) and getattr (component , "custom_id" , None ) == component_id :
145153 return component
146154 elif isinstance (component_id , int ) and getattr (component , "id" , None ) == component_id :
147155 return component
148156
157+ return None
158+
149159
150160class ModalComponentMixin (ABC , Generic [P ]):
151161 """A component that can be used in a modal.
0 commit comments