Skip to content

Commit

Permalink
Add message property to views (#1446)
Browse files Browse the repository at this point in the history
  • Loading branch information
WhoIsConch authored Jun 28, 2022
1 parent 525d953 commit 56fb961
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions discord/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}>"
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 56fb961

Please sign in to comment.