Browse Source

Allow Webhook.send to send ephemeral messages

This is only available for application webhooks
pull/6997/head
Rapptz 4 years ago
parent
commit
db58e628ba
  1. 23
      discord/webhook/async_.py

23
discord/webhook/async_.py

@ -418,6 +418,7 @@ def handle_message_parameters(
username: str = MISSING, username: str = MISSING,
avatar_url: str = MISSING, avatar_url: str = MISSING,
tts: bool = False, tts: bool = False,
ephemeral: bool = False,
file: File = MISSING, file: File = MISSING,
files: List[File] = MISSING, files: List[File] = MISSING,
embed: Optional[Embed] = MISSING, embed: Optional[Embed] = MISSING,
@ -453,6 +454,8 @@ def handle_message_parameters(
payload['avatar_url'] = str(avatar_url) payload['avatar_url'] = str(avatar_url)
if username: if username:
payload['username'] = username payload['username'] = username
if ephemeral:
payload['flags'] = 64
if allowed_mentions: if allowed_mentions:
if previous_allowed_mentions is not None: if previous_allowed_mentions is not None:
@ -1139,6 +1142,7 @@ class Webhook(BaseWebhook):
username: str = MISSING, username: str = MISSING,
avatar_url: str = MISSING, avatar_url: str = MISSING,
tts: bool = MISSING, tts: bool = MISSING,
ephemeral: bool = MISSING,
file: File = MISSING, file: File = MISSING,
files: List[File] = MISSING, files: List[File] = MISSING,
embed: Embed = MISSING, embed: Embed = MISSING,
@ -1156,6 +1160,7 @@ class Webhook(BaseWebhook):
username: str = MISSING, username: str = MISSING,
avatar_url: str = MISSING, avatar_url: str = MISSING,
tts: bool = MISSING, tts: bool = MISSING,
ephemeral: bool = MISSING,
file: File = MISSING, file: File = MISSING,
files: List[File] = MISSING, files: List[File] = MISSING,
embed: Embed = MISSING, embed: Embed = MISSING,
@ -1172,6 +1177,7 @@ class Webhook(BaseWebhook):
username: str = MISSING, username: str = MISSING,
avatar_url: str = MISSING, avatar_url: str = MISSING,
tts: bool = False, tts: bool = False,
ephemeral: bool = False,
file: File = MISSING, file: File = MISSING,
files: List[File] = MISSING, files: List[File] = MISSING,
embed: Embed = MISSING, embed: Embed = MISSING,
@ -1199,7 +1205,8 @@ class Webhook(BaseWebhook):
wait: :class:`bool` wait: :class:`bool`
Whether the server should wait before sending a response. This essentially Whether the server should wait before sending a response. This essentially
means that the return type of this function changes from ``None`` to means that the return type of this function changes from ``None`` to
a :class:`WebhookMessage` if set to ``True``. a :class:`WebhookMessage` if set to ``True``. If the type of webhook
is :attr:`WebhookType.application` then this is always set to ``True``.
username: :class:`str` username: :class:`str`
The username to send with this message. If no username is provided The username to send with this message. If no username is provided
then the default username for the webhook is used. then the default username for the webhook is used.
@ -1208,6 +1215,9 @@ class Webhook(BaseWebhook):
then the default avatar for the webhook is used. then the default avatar for the webhook is used.
tts: :class:`bool` tts: :class:`bool`
Indicates if the message should be sent using text-to-speech. Indicates if the message should be sent using text-to-speech.
ephemeral: :class:`bool`
Indicates if the message should only be visible to the user.
This is only available to :attr:`WebhookType.application` webhooks.
file: :class:`File` file: :class:`File`
The file to upload. This cannot be mixed with ``files`` parameter. The file to upload. This cannot be mixed with ``files`` parameter.
files: List[:class:`File`] files: List[:class:`File`]
@ -1237,7 +1247,8 @@ class Webhook(BaseWebhook):
ValueError ValueError
The length of ``embeds`` was invalid. The length of ``embeds`` was invalid.
InvalidArgument InvalidArgument
There was no token associated with this webhook. There was no token associated with this webhook or ``ephemeral``
was passed with the improper webhook type.
Returns Returns
--------- ---------
@ -1252,6 +1263,13 @@ class Webhook(BaseWebhook):
if content is None: if content is None:
content = MISSING content = MISSING
application_webhook = self.type is WebhookType.application
if ephemeral and not application_webhook:
raise InvalidArgument('ephemeral messages can only be sent from application webhooks')
if application_webhook:
wait = True
params = handle_message_parameters( params = handle_message_parameters(
content=content, content=content,
username=username, username=username,
@ -1261,6 +1279,7 @@ class Webhook(BaseWebhook):
files=files, files=files,
embed=embed, embed=embed,
embeds=embeds, embeds=embeds,
ephemeral=ephemeral,
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions, previous_allowed_mentions=previous_mentions,
) )

Loading…
Cancel
Save