aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadir Chowdhury <[email protected]>2021-04-16 16:27:15 +0100
committerGitHub <[email protected]>2021-04-16 11:27:15 -0400
commit57dbb37a52404b8fa5d00672a34bde6b62321415 (patch)
treec685ff869e6d9ea8b692b1a170a7cf77dba5471d
parentRemove Sticker.preview_image (diff)
downloaddiscord.py-57dbb37a52404b8fa5d00672a34bde6b62321415.tar.xz
discord.py-57dbb37a52404b8fa5d00672a34bde6b62321415.zip
Add `fetch_message` for webhooks
-rw-r--r--discord/http.py13
-rw-r--r--discord/webhook/async_.py67
-rw-r--r--discord/webhook/sync.py65
3 files changed, 139 insertions, 6 deletions
diff --git a/discord/http.py b/discord/http.py
index 6d6c641d..6aba2d21 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -1208,6 +1208,19 @@ class HTTPClient:
)
return self.request(r)
+ def get_original_interaction_response(
+ self,
+ application_id,
+ token,
+ ):
+ r = Route(
+ 'GET',
+ '/webhooks/{application_id}/{interaction_token}/messages/@original',
+ application_id=application_id,
+ interaction_token=token,
+ )
+ return self.request(r)
+
def edit_original_interaction_response(
self,
application_id,
diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py
index 59fe7e2f..aadc752c 100644
--- a/discord/webhook/async_.py
+++ b/discord/webhook/async_.py
@@ -268,6 +268,23 @@ class AsyncWebhookAdapter:
route = Route('POST', '/webhooks/{webhook_id}/{webhook_token}', webhook_id=webhook_id, webhook_token=token)
return self.request(route, session, payload=payload, multipart=multipart, files=files, params=params)
+ def get_webhook_message(
+ self,
+ webhook_id: int,
+ token: str,
+ message_id: int,
+ *,
+ session: aiohttp.ClientSession,
+ ):
+ route = Route(
+ 'GET',
+ '/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
+ webhook_id=webhook_id,
+ webhook_token=token,
+ message_id=message_id,
+ )
+ return self.request(route, session)
+
def edit_webhook_message(
self,
webhook_id: int,
@@ -1125,6 +1142,11 @@ class Webhook(BaseWebhook):
)
self._update(data)
+ def _create_message(self, data):
+ state = _WebhookState(self, parent=self._state)
+ channel = self.channel or Object(id=int(data['channel_id']))
+ return WebhookMessage(data=data, state=state, channel=channel)
+
@overload
async def send(
self,
@@ -1269,9 +1291,48 @@ class Webhook(BaseWebhook):
wait=wait,
)
if wait:
- state = _WebhookState(self, parent=self._state)
- channel = self.channel or Object(id=int(data['channel_id']))
- return WebhookMessage(data=data, state=state, channel=channel)
+ return self._create_message(data)
+
+ async def fetch_message(self, id: int) -> WebhookMessage:
+ """|coro|
+
+ Retrieves a single :class:`~discord.WebhookMessage` owned by this webhook.
+
+ .. versionadded:: 2.0
+
+ Parameters
+ ------------
+ id: :class:`int`
+ The message ID to look for.
+
+ Raises
+ --------
+ ~discord.NotFound
+ The specified message was not found.
+ ~discord.Forbidden
+ You do not have the permissions required to get a message.
+ ~discord.HTTPException
+ Retrieving the message failed.
+ InvalidArgument
+ There was no token associated with this webhook.
+
+ Returns
+ --------
+ :class:`~discord.WebhookMessage`
+ The message asked for.
+ """
+
+ if self.token is None:
+ raise InvalidArgument('This webhook does not have a token associated with it')
+
+ adapter = async_context.get()
+ data = await adapter.get_webhook_message(
+ self.id,
+ self.token,
+ id,
+ session=self.session,
+ )
+ return self._create_message(data)
async def edit_message(
self,
diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py
index 0e2fe6d0..98bb528e 100644
--- a/discord/webhook/sync.py
+++ b/discord/webhook/sync.py
@@ -259,6 +259,23 @@ class WebhookAdapter:
route = Route('POST', '/webhooks/{webhook_id}/{webhook_token}', webhook_id=webhook_id, webhook_token=token)
return self.request(route, session, payload=payload, multipart=multipart, files=files, params=params)
+ def get_webhook_message(
+ self,
+ webhook_id: int,
+ token: str,
+ message_id: int,
+ *,
+ session: Session,
+ ):
+ route = Route(
+ 'GET',
+ '/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}',
+ webhook_id=webhook_id,
+ webhook_token=token,
+ message_id=message_id,
+ )
+ return self.request(route, session)
+
def edit_webhook_message(
self,
webhook_id: int,
@@ -704,6 +721,11 @@ class SyncWebhook(BaseWebhook):
data = adapter.edit_webhook_with_token(self.id, self.token, payload=payload, session=self.session, reason=reason)
self._update(data)
+ def _create_message(self, data):
+ state = _WebhookState(self, parent=self._state)
+ channel = self.channel or Object(id=int(data['channel_id']))
+ return SyncWebhookMessage(data=data, state=state, channel=channel)
+
@overload
def send(
self,
@@ -846,9 +868,46 @@ class SyncWebhook(BaseWebhook):
wait=wait,
)
if wait:
- state = _WebhookState(self, parent=self._state)
- channel = self.channel or Object(id=int(data['channel_id']))
- return SyncWebhookMessage(data=data, state=state, channel=channel)
+ return self._create_message(data)
+
+ def fetch_message(self, id: int) -> SyncWebhookMessage:
+ """Retrieves a single :class:`~discord.SyncWebhookMessage` owned by this webhook.
+
+ .. versionadded:: 2.0
+
+ Parameters
+ ------------
+ id: :class:`int`
+ The message ID to look for.
+
+ Raises
+ --------
+ ~discord.NotFound
+ The specified message was not found.
+ ~discord.Forbidden
+ You do not have the permissions required to get a message.
+ ~discord.HTTPException
+ Retrieving the message failed.
+ InvalidArgument
+ There was no token associated with this webhook.
+
+ Returns
+ --------
+ :class:`~discord.SyncWebhookMessage`
+ The message asked for.
+ """
+
+ if self.token is None:
+ raise InvalidArgument('This webhook does not have a token associated with it')
+
+ adapter: WebhookAdapter = _context.adapter
+ data = adapter.get_webhook_message(
+ self.id,
+ self.token,
+ id,
+ session=self.session,
+ )
+ return self._create_message(data)
def edit_message(
self,