Browse Source

chore: dynamic items

pull/10166/head
DA-344 2 weeks ago
parent
commit
0b25cf7a99
  1. 9
      discord/ui/dynamic.py
  2. 3
      discord/ui/view.py

9
discord/ui/dynamic.py

@ -45,7 +45,7 @@ else:
V = TypeVar('V', bound='BaseView', covariant=True) V = TypeVar('V', bound='BaseView', covariant=True)
class DynamicItem(Generic[BaseT], Item['BaseView']): class DynamicItem(Generic[BaseT, V], Item[V]):
"""Represents an item with a dynamic ``custom_id`` that can be used to store state within """Represents an item with a dynamic ``custom_id`` that can be used to store state within
that ``custom_id``. that ``custom_id``.
@ -57,9 +57,10 @@ class DynamicItem(Generic[BaseT], Item['BaseView']):
and should not be used long term. Their only purpose is to act as a "template" and should not be used long term. Their only purpose is to act as a "template"
for the actual dispatched item. for the actual dispatched item.
When this item is generated, :attr:`view` is set to a regular :class:`View` instance When this item is generated, :attr:`view` is set to a regular :class:`View` instance,
from the original message given from the interaction. This means that custom view but to a :class:`LayoutView` if the component was sent with one, this is obtained from
subclasses cannot be accessed from this item. the original message given from the interaction. This means that custom view subclasses
cannot be accessed from this item.
.. versionadded:: 2.4 .. versionadded:: 2.4

3
discord/ui/view.py

@ -948,7 +948,8 @@ class ViewStore:
if interaction.message is None: if interaction.message is None:
return return
view = View.from_message(interaction.message, timeout=None) view_cls = View if not interaction.message.flags.components_v2 else LayoutView
view = view_cls.from_message(interaction.message, timeout=None)
try: try:
base_item_index, base_item = next( base_item_index, base_item = next(

Loading…
Cancel
Save