Skip to content

Commit be9eb51

Browse files
authored
add Webhook.parent
1 parent 3f3ae31 commit be9eb51

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

discord/interactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def followup(self) -> Webhook:
403403
"type": 3,
404404
"token": self.token,
405405
}
406-
return Webhook.from_state(data=payload, state=self._state)
406+
return Webhook.from_state(data=payload, state=self._state, parent=self)
407407

408408
def is_guild_authorised(self) -> bool:
409409
""":class:`bool`: Checks if the interaction is guild authorised.
@@ -1105,11 +1105,11 @@ async def send_message(
11051105
self._responded = True
11061106
await self._process_callback_response(callback_response)
11071107
if view:
1108+
view.parent = self._parent
11081109
if not view.is_finished():
11091110
if ephemeral and view.timeout is None:
11101111
view.timeout = 15 * 60.0
11111112

1112-
view.parent = self._parent
11131113
if view.is_dispatchable():
11141114
self._parent._state.store_view(view)
11151115

discord/webhook/async_.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
from ..file import File
7575
from ..guild import Guild
7676
from ..http import Response
77+
from ..interactions import Interaction
7778
from ..mentions import AllowedMentions
7879
from ..poll import Poll
7980
from ..state import ConnectionState
@@ -1203,6 +1204,12 @@ async def foo():
12031204
Only given if :attr:`type` is :attr:`WebhookType.channel_follower`.
12041205
12051206
.. versionadded:: 2.0
1207+
1208+
parent: Optional[:class:`Interaction`]
1209+
The interaction this webhook belongs to.
1210+
Only set if :attr:`type` is :attr:`WebhookType.application`.
1211+
1212+
.. versionadded:: 2.7
12061213
"""
12071214

12081215
__slots__: tuple[str, ...] = ("session", "proxy", "proxy_auth")
@@ -1215,11 +1222,13 @@ def __init__(
12151222
proxy_auth: aiohttp.BasicAuth | None = None,
12161223
token: str | None = None,
12171224
state=None,
1225+
parent: Interaction | None = None
12181226
):
12191227
super().__init__(data, token, state)
12201228
self.session = session
12211229
self.proxy: str | None = proxy
12221230
self.proxy_auth: aiohttp.BasicAuth | None = proxy_auth
1231+
self.parent: Interaction | None = parent
12231232

12241233
def __repr__(self):
12251234
return f"<Webhook id={self.id!r}>"
@@ -1867,6 +1876,8 @@ async def send(
18671876
if view and not view.is_finished():
18681877
message_id = None if msg is None else msg.id
18691878
view.message = None if msg is None else msg
1879+
if self.parent and not view.parent:
1880+
view.parent = self.parent
18701881
if msg:
18711882
view.refresh(msg.components)
18721883
if view.is_dispatchable():

0 commit comments

Comments
 (0)