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)
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
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"
for the actual dispatched item.
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
subclasses cannot be accessed from this item.
When this item is generated, :attr:`view` is set to a regular :class:`View` instance,
but to a :class:`LayoutView` if the component was sent with one, this is obtained from
the original message given from the interaction. This means that custom view subclasses
cannot be accessed from this item.
.. versionadded:: 2.4

3
discord/ui/view.py

@ -948,7 +948,8 @@ class ViewStore:
if interaction.message is None:
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:
base_item_index, base_item = next(

Loading…
Cancel
Save