diff --git a/discord/abc.py b/discord/abc.py index 44657d26b4..90a7256c8e 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -1534,6 +1534,7 @@ async def send( ret = state.create_message(channel=channel, data=data) if view: state.store_view(view, ret.id) + view.message = ret if delete_after is not None: await ret.delete(delay=delete_after) diff --git a/discord/ui/view.py b/discord/ui/view.py index 6b3fec5a5a..f06ca7cc1f 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -144,6 +144,9 @@ class View: If ``None`` then there is no timeout. children: List[:class:`Item`] The list of children attached to this view. + message: Optional[:class:`Message`] + The message that this view is attached to. + If ``None`` then the view has not been sent with a message. """ __discord_ui_view__: ClassVar[bool] = True @@ -181,6 +184,7 @@ def __init__(self, *items: Item, timeout: Optional[float] = 180.0): self.__timeout_expiry: Optional[float] = None self.__timeout_task: Optional[asyncio.Task[None]] = None self.__stopped: asyncio.Future[bool] = loop.create_future() + self._message: Optional[Message] = None def __repr__(self) -> str: return f"<{self.__class__.__name__} timeout={self.timeout} children={len(self.children)}>" @@ -491,6 +495,13 @@ def enable_all_items(self, *, exclusions: Optional[List[Item]] = None) -> None: if exclusions is None or child not in exclusions: child.disabled = False + @property + def message(self): + return self._message + + @message.setter + def message(self, value): + self._message = value class ViewStore: def __init__(self, state: ConnectionState):