mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
Add support for dynamic items that parse custom_id for state
This commit is contained in:
@ -72,6 +72,7 @@ from .backoff import ExponentialBackoff
|
||||
from .webhook import Webhook
|
||||
from .appinfo import AppInfo
|
||||
from .ui.view import View
|
||||
from .ui.dynamic import DynamicItem
|
||||
from .stage_instance import StageInstance
|
||||
from .threads import Thread
|
||||
from .sticker import GuildSticker, StandardSticker, StickerPack, _sticker_factory
|
||||
@ -111,6 +112,7 @@ if TYPE_CHECKING:
|
||||
from .scheduled_event import ScheduledEvent
|
||||
from .threads import ThreadMember
|
||||
from .types.guild import Guild as GuildPayload
|
||||
from .ui.item import Item
|
||||
from .voice_client import VoiceProtocol
|
||||
from .audit_logs import AuditLogEntry
|
||||
|
||||
@ -2678,6 +2680,30 @@ class Client:
|
||||
data = await state.http.start_private_message(user.id)
|
||||
return state.add_dm_channel(data)
|
||||
|
||||
def add_dynamic_items(self, *items: Type[DynamicItem[Item[Any]]]) -> None:
|
||||
r"""Registers a :class:`~discord.ui.DynamicItem` class for persistent listening.
|
||||
|
||||
This method accepts *class types* rather than instances.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
\*items: Type[:class:`~discord.ui.DynamicItem`]
|
||||
The classes of dynamic items to add.
|
||||
|
||||
Raises
|
||||
-------
|
||||
TypeError
|
||||
The class is not a subclass of :class:`~discord.ui.DynamicItem`.
|
||||
"""
|
||||
|
||||
for item in items:
|
||||
if not issubclass(item, DynamicItem):
|
||||
raise TypeError(f'expected subclass of DynamicItem not {item.__name__}')
|
||||
|
||||
self._connection.store_dynamic_items(*items)
|
||||
|
||||
def add_view(self, view: View, *, message_id: Optional[int] = None) -> None:
|
||||
"""Registers a :class:`~discord.ui.View` for persistent listening.
|
||||
|
||||
|
Reference in New Issue
Block a user