Skip to content

Commit 9496c72

Browse files
authored
Merge pull request #335 from Makiyu-py/issue321-update
Added Support for thread_id on Webhook Messages
2 parents 8d37529 + 1d09bf2 commit 9496c72

File tree

2 files changed

+96
-10
lines changed

2 files changed

+96
-10
lines changed

discord/webhook/async_.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,21 @@ def get_webhook_message(
274274
message_id: int,
275275
*,
276276
session: aiohttp.ClientSession,
277+
thread_id: Optional[int] = None,
277278
) -> Response[MessagePayload]:
279+
params = {}
280+
281+
if thread_id:
282+
params['thread_id'] = thread_id
283+
278284
route = Route(
279285
'GET',
280286
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
281287
webhook_id=webhook_id,
282288
webhook_token=token,
283289
message_id=message_id,
284290
)
285-
return self.request(route, session)
291+
return self.request(route, session, params=params)
286292

287293
def edit_webhook_message(
288294
self,
@@ -291,18 +297,24 @@ def edit_webhook_message(
291297
message_id: int,
292298
*,
293299
session: aiohttp.ClientSession,
300+
thread_id: Optional[int] = None,
294301
payload: Optional[Dict[str, Any]] = None,
295302
multipart: Optional[List[Dict[str, Any]]] = None,
296303
files: Optional[List[File]] = None,
297304
) -> Response[Message]:
305+
params = {}
306+
307+
if thread_id:
308+
params['thread_id'] = thread_id
309+
298310
route = Route(
299311
'PATCH',
300312
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
301313
webhook_id=webhook_id,
302314
webhook_token=token,
303315
message_id=message_id,
304316
)
305-
return self.request(route, session, payload=payload, multipart=multipart, files=files)
317+
return self.request(route, session, params=params, payload=payload, multipart=multipart, files=files)
306318

307319
def delete_webhook_message(
308320
self,
@@ -311,15 +323,21 @@ def delete_webhook_message(
311323
message_id: int,
312324
*,
313325
session: aiohttp.ClientSession,
326+
thread_id: Optional[int] = None,
314327
) -> Response[None]:
328+
params = {}
329+
330+
if thread_id:
331+
params['thread_id'] = thread_id
332+
315333
route = Route(
316334
'DELETE',
317335
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
318336
webhook_id=webhook_id,
319337
webhook_token=token,
320338
message_id=message_id,
321339
)
322-
return self.request(route, session)
340+
return self.request(route, session, params=params)
323341

324342
def fetch_webhook(
325343
self,
@@ -1429,7 +1447,12 @@ async def send(
14291447

14301448
return msg
14311449

1432-
async def fetch_message(self, id: int, /) -> WebhookMessage:
1450+
async def fetch_message(
1451+
self,
1452+
id: int,
1453+
*,
1454+
thread_id: Optional[int] = None
1455+
) -> WebhookMessage:
14331456
"""|coro|
14341457
14351458
Retrieves a single :class:`~discord.WebhookMessage` owned by this webhook.
@@ -1440,6 +1463,8 @@ async def fetch_message(self, id: int, /) -> WebhookMessage:
14401463
------------
14411464
id: :class:`int`
14421465
The message ID to look for.
1466+
thread_id: Optional[:class:`int`]
1467+
The ID of the thread that contains the message.
14431468
14441469
Raises
14451470
--------
@@ -1467,6 +1492,7 @@ async def fetch_message(self, id: int, /) -> WebhookMessage:
14671492
self.token,
14681493
id,
14691494
session=self.session,
1495+
thread_id=thread_id,
14701496
)
14711497
return self._create_message(data)
14721498

@@ -1481,6 +1507,7 @@ async def edit_message(
14811507
files: List[File] = MISSING,
14821508
view: Optional[View] = MISSING,
14831509
allowed_mentions: Optional[AllowedMentions] = None,
1510+
thread: Optional[Snowflake] = MISSING
14841511
) -> WebhookMessage:
14851512
"""|coro|
14861513
@@ -1523,6 +1550,8 @@ async def edit_message(
15231550
:meth:`send`.
15241551
15251552
.. versionadded:: 2.0
1553+
thread: Optional[:class:`~discord.abc.Snowflake`]
1554+
The thread that contains the message.
15261555
15271556
Raises
15281557
-------
@@ -1564,12 +1593,18 @@ async def edit_message(
15641593
allowed_mentions=allowed_mentions,
15651594
previous_allowed_mentions=previous_mentions,
15661595
)
1596+
1597+
thread_id: Optional[int] = None
1598+
if thread_id is not MISSING:
1599+
thread_id = thread.id
1600+
15671601
adapter = async_context.get()
15681602
data = await adapter.edit_webhook_message(
15691603
self.id,
15701604
self.token,
15711605
message_id,
15721606
session=self.session,
1607+
thread_id=thread_id,
15731608
payload=params.payload,
15741609
multipart=params.multipart,
15751610
files=params.files,
@@ -1580,7 +1615,12 @@ async def edit_message(
15801615
self._state.store_view(view, message_id)
15811616
return message
15821617

1583-
async def delete_message(self, message_id: int, /) -> None:
1618+
async def delete_message(
1619+
self,
1620+
message_id: int,
1621+
*,
1622+
thread_id: Optional[int] = None
1623+
) -> None:
15841624
"""|coro|
15851625
15861626
Deletes a message owned by this webhook.
@@ -1594,6 +1634,8 @@ async def delete_message(self, message_id: int, /) -> None:
15941634
------------
15951635
message_id: :class:`int`
15961636
The message ID to delete.
1637+
thread_id: Optional[:class:`int`]
1638+
The ID of the thread that contains the message.
15971639
15981640
Raises
15991641
-------
@@ -1611,4 +1653,5 @@ async def delete_message(self, message_id: int, /) -> None:
16111653
self.token,
16121654
message_id,
16131655
session=self.session,
1656+
thread_id=thread_id,
16141657
)

discord/webhook/sync.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,21 @@ def get_webhook_message(
281281
message_id: int,
282282
*,
283283
session: Session,
284+
thread_id: Optional[int] = None,
284285
):
286+
params = {}
287+
288+
if thread_id:
289+
params['thread_id'] = thread_id
290+
285291
route = Route(
286292
'GET',
287293
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
288294
webhook_id=webhook_id,
289295
webhook_token=token,
290296
message_id=message_id,
291297
)
292-
return self.request(route, session)
298+
return self.request(route, session, params=params)
293299

294300
def edit_webhook_message(
295301
self,
@@ -298,18 +304,24 @@ def edit_webhook_message(
298304
message_id: int,
299305
*,
300306
session: Session,
307+
thread_id: Optional[int] = None,
301308
payload: Optional[Dict[str, Any]] = None,
302309
multipart: Optional[List[Dict[str, Any]]] = None,
303310
files: Optional[List[File]] = None,
304311
):
312+
params = {}
313+
314+
if thread_id:
315+
params['thread_id'] = thread_id
316+
305317
route = Route(
306318
'PATCH',
307319
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
308320
webhook_id=webhook_id,
309321
webhook_token=token,
310322
message_id=message_id,
311323
)
312-
return self.request(route, session, payload=payload, multipart=multipart, files=files)
324+
return self.request(route, session, params=params, payload=payload, multipart=multipart, files=files)
313325

314326
def delete_webhook_message(
315327
self,
@@ -318,15 +330,21 @@ def delete_webhook_message(
318330
message_id: int,
319331
*,
320332
session: Session,
333+
thread_id: Optional[int] = None,
321334
):
335+
params = {}
336+
337+
if thread_id:
338+
params['thread_id'] = thread_id
339+
322340
route = Route(
323341
'DELETE',
324342
'/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
325343
webhook_id=webhook_id,
326344
webhook_token=token,
327345
message_id=message_id,
328346
)
329-
return self.request(route, session)
347+
return self.request(route, session, params=params)
330348

331349
def fetch_webhook(
332350
self,
@@ -920,7 +938,12 @@ def send(
920938
if wait:
921939
return self._create_message(data)
922940

923-
def fetch_message(self, id: int, /) -> SyncWebhookMessage:
941+
def fetch_message(
942+
self,
943+
id: int,
944+
*,
945+
thread_id: Optional[int] = None
946+
) -> SyncWebhookMessage:
924947
"""Retrieves a single :class:`~discord.SyncWebhookMessage` owned by this webhook.
925948
926949
.. versionadded:: 2.0
@@ -929,6 +952,8 @@ def fetch_message(self, id: int, /) -> SyncWebhookMessage:
929952
------------
930953
id: :class:`int`
931954
The message ID to look for.
955+
thread_id: Optional[:class:`int`]
956+
The ID of the thread that contains the message.
932957
933958
Raises
934959
--------
@@ -956,6 +981,7 @@ def fetch_message(self, id: int, /) -> SyncWebhookMessage:
956981
self.token,
957982
id,
958983
session=self.session,
984+
thread_id=thread_id,
959985
)
960986
return self._create_message(data)
961987

@@ -969,6 +995,7 @@ def edit_message(
969995
file: File = MISSING,
970996
files: List[File] = MISSING,
971997
allowed_mentions: Optional[AllowedMentions] = None,
998+
thread: Optional[Snowflake] = MISSING,
972999
) -> SyncWebhookMessage:
9731000
"""Edits a message owned by this webhook.
9741001
@@ -996,6 +1023,8 @@ def edit_message(
9961023
allowed_mentions: :class:`AllowedMentions`
9971024
Controls the mentions being processed in this message.
9981025
See :meth:`.abc.Messageable.send` for more information.
1026+
thread: Optional[:class:`~discord.abc.Snowflake`]
1027+
The thread that contains the message.
9991028
10001029
Raises
10011030
-------
@@ -1025,18 +1054,29 @@ def edit_message(
10251054
previous_allowed_mentions=previous_mentions,
10261055
)
10271056
adapter: WebhookAdapter = _get_webhook_adapter()
1057+
1058+
thread_id: Optional[int] = None
1059+
if thread is not MISSING:
1060+
thread_id = thread.id
1061+
10281062
data = adapter.edit_webhook_message(
10291063
self.id,
10301064
self.token,
10311065
message_id,
10321066
session=self.session,
1067+
thread_id=thread_id,
10331068
payload=params.payload,
10341069
multipart=params.multipart,
10351070
files=params.files,
10361071
)
10371072
return self._create_message(data)
10381073

1039-
def delete_message(self, message_id: int, /) -> None:
1074+
def delete_message(
1075+
self,
1076+
message_id: int,
1077+
*,
1078+
thread_id: Optional[int] = None
1079+
) -> None:
10401080
"""Deletes a message owned by this webhook.
10411081
10421082
This is a lower level interface to :meth:`WebhookMessage.delete` in case
@@ -1048,6 +1088,8 @@ def delete_message(self, message_id: int, /) -> None:
10481088
------------
10491089
message_id: :class:`int`
10501090
The message ID to delete.
1091+
thread_id: Optional[:class:`int`]
1092+
The ID of the thread that contains the message.
10511093
10521094
Raises
10531095
-------
@@ -1065,4 +1107,5 @@ def delete_message(self, message_id: int, /) -> None:
10651107
self.token,
10661108
message_id,
10671109
session=self.session,
1110+
thread_id=thread_id,
10681111
)

0 commit comments

Comments
 (0)