Add support for components V2

Co-authored-by: Michael H <michael@michaelhall.tech>
Co-authored-by: Soheab <33902984+Soheab@users.noreply.github.com>
Co-authored-by: owocado <24418520+owocado@users.noreply.github.com>
Co-authored-by: Jay3332 <40323796+jay3332@users.noreply.github.com>
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
This commit is contained in:
DA344
2025-08-14 02:37:23 +02:00
committed by GitHub
parent 6ec2e5329b
commit 50caa3c82c
33 changed files with 4214 additions and 298 deletions

View File

@ -72,7 +72,7 @@ from .object import Object
from .backoff import ExponentialBackoff
from .webhook import Webhook
from .appinfo import AppInfo
from .ui.view import View
from .ui.view import BaseView
from .ui.dynamic import DynamicItem
from .stage_instance import StageInstance
from .threads import Thread
@ -3156,7 +3156,7 @@ class Client:
self._connection.remove_dynamic_items(*items)
def add_view(self, view: View, *, message_id: Optional[int] = None) -> None:
def add_view(self, view: BaseView, *, message_id: Optional[int] = None) -> None:
"""Registers a :class:`~discord.ui.View` for persistent listening.
This method should be used for when a view is comprised of components
@ -3166,7 +3166,7 @@ class Client:
Parameters
------------
view: :class:`discord.ui.View`
view: Union[:class:`discord.ui.View`, :class:`discord.ui.LayoutView`]
The view to register for dispatching.
message_id: Optional[:class:`int`]
The message ID that the view is attached to. This is currently used to
@ -3182,7 +3182,7 @@ class Client:
and all their components have an explicitly provided custom_id.
"""
if not isinstance(view, View):
if not isinstance(view, BaseView):
raise TypeError(f'expected an instance of View not {view.__class__.__name__}')
if not view.is_persistent():
@ -3194,8 +3194,8 @@ class Client:
self._connection.store_view(view, message_id)
@property
def persistent_views(self) -> Sequence[View]:
"""Sequence[:class:`.View`]: A sequence of persistent views added to the client.
def persistent_views(self) -> Sequence[BaseView]:
"""Sequence[Union[:class:`.View`, :class:`.LayoutView`]]: A sequence of persistent views added to the client.
.. versionadded:: 2.0
"""