Add fetch_message
for webhooks
This commit is contained in:
parent
b610998491
commit
57dbb37a52
@ -1208,6 +1208,19 @@ class HTTPClient:
|
|||||||
)
|
)
|
||||||
return self.request(r)
|
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(
|
def edit_original_interaction_response(
|
||||||
self,
|
self,
|
||||||
application_id,
|
application_id,
|
||||||
|
@ -268,6 +268,23 @@ class AsyncWebhookAdapter:
|
|||||||
route = Route('POST', '/webhooks/{webhook_id}/{webhook_token}', webhook_id=webhook_id, webhook_token=token)
|
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)
|
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(
|
def edit_webhook_message(
|
||||||
self,
|
self,
|
||||||
webhook_id: int,
|
webhook_id: int,
|
||||||
@ -1125,6 +1142,11 @@ class Webhook(BaseWebhook):
|
|||||||
)
|
)
|
||||||
self._update(data)
|
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
|
@overload
|
||||||
async def send(
|
async def send(
|
||||||
self,
|
self,
|
||||||
@ -1269,9 +1291,48 @@ class Webhook(BaseWebhook):
|
|||||||
wait=wait,
|
wait=wait,
|
||||||
)
|
)
|
||||||
if wait:
|
if wait:
|
||||||
state = _WebhookState(self, parent=self._state)
|
return self._create_message(data)
|
||||||
channel = self.channel or Object(id=int(data['channel_id']))
|
|
||||||
return WebhookMessage(data=data, state=state, channel=channel)
|
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(
|
async def edit_message(
|
||||||
self,
|
self,
|
||||||
|
@ -259,6 +259,23 @@ class WebhookAdapter:
|
|||||||
route = Route('POST', '/webhooks/{webhook_id}/{webhook_token}', webhook_id=webhook_id, webhook_token=token)
|
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)
|
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(
|
def edit_webhook_message(
|
||||||
self,
|
self,
|
||||||
webhook_id: int,
|
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)
|
data = adapter.edit_webhook_with_token(self.id, self.token, payload=payload, session=self.session, reason=reason)
|
||||||
self._update(data)
|
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
|
@overload
|
||||||
def send(
|
def send(
|
||||||
self,
|
self,
|
||||||
@ -846,9 +868,46 @@ class SyncWebhook(BaseWebhook):
|
|||||||
wait=wait,
|
wait=wait,
|
||||||
)
|
)
|
||||||
if wait:
|
if wait:
|
||||||
state = _WebhookState(self, parent=self._state)
|
return self._create_message(data)
|
||||||
channel = self.channel or Object(id=int(data['channel_id']))
|
|
||||||
return SyncWebhookMessage(data=data, state=state, channel=channel)
|
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(
|
def edit_message(
|
||||||
self,
|
self,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user