aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-29 00:35:13 -0400
committerRapptz <[email protected]>2021-05-29 00:44:08 -0400
commit732c5384fd82f8108091365556c95b564e54391f (patch)
tree54ba2d62920ac01aaafd6bad8029cef0ca369e19
parentAdd support for bot integrations (diff)
downloaddiscord.py-732c5384fd82f8108091365556c95b564e54391f.tar.xz
discord.py-732c5384fd82f8108091365556c95b564e54391f.zip
Allow registering a View for persistent long term dispatching
-rw-r--r--discord/client.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/discord/client.py b/discord/client.py
index 1a33394a..60226012 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -55,6 +55,7 @@ from .backoff import ExponentialBackoff
from .webhook import Webhook
from .iterators import GuildIterator
from .appinfo import AppInfo
+from .ui.view import View
__all__ = (
'Client',
@@ -1379,3 +1380,29 @@ class Client:
data = await state.http.start_private_message(user.id)
return state.add_dm_channel(data)
+
+ def add_view(self, view: View, *, 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
+ that last longer than the lifecycle of the program.
+
+ Parameters
+ ------------
+ view: :class:`discord.ui.View`
+ 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
+ refresh the view's state during message update events. If not given
+ then message update events are not propagated for the view.
+
+ Raises
+ -------
+ TypeError
+ A view was not passed.
+ """
+
+ if not isinstance(view, View):
+ raise TypeError(f'expected an instance of View not {view.__class__!r}')
+
+ self._connection.store_view(view, message_id)