aboutsummaryrefslogtreecommitdiff
path: root/discord/webhook/async_.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-30 10:29:17 -0400
committerRapptz <[email protected]>2021-05-30 10:29:29 -0400
commitdb58e628ba9b24b939dbbab75c93fe47ddd9dde0 (patch)
treec81e17056da8034f30c1ea4e07d328689ef8adf4 /discord/webhook/async_.py
parentAdd WebhookType.application (diff)
downloaddiscord.py-db58e628ba9b24b939dbbab75c93fe47ddd9dde0.tar.xz
discord.py-db58e628ba9b24b939dbbab75c93fe47ddd9dde0.zip
Allow Webhook.send to send ephemeral messages
This is only available for application webhooks
Diffstat (limited to 'discord/webhook/async_.py')
-rw-r--r--discord/webhook/async_.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py
index 3535c58a..523fec74 100644
--- a/discord/webhook/async_.py
+++ b/discord/webhook/async_.py
@@ -418,6 +418,7 @@ def handle_message_parameters(
username: str = MISSING,
avatar_url: str = MISSING,
tts: bool = False,
+ ephemeral: bool = False,
file: File = MISSING,
files: List[File] = MISSING,
embed: Optional[Embed] = MISSING,
@@ -453,6 +454,8 @@ def handle_message_parameters(
payload['avatar_url'] = str(avatar_url)
if username:
payload['username'] = username
+ if ephemeral:
+ payload['flags'] = 64
if allowed_mentions:
if previous_allowed_mentions is not None:
@@ -1139,6 +1142,7 @@ class Webhook(BaseWebhook):
username: str = MISSING,
avatar_url: str = MISSING,
tts: bool = MISSING,
+ ephemeral: bool = MISSING,
file: File = MISSING,
files: List[File] = MISSING,
embed: Embed = MISSING,
@@ -1156,6 +1160,7 @@ class Webhook(BaseWebhook):
username: str = MISSING,
avatar_url: str = MISSING,
tts: bool = MISSING,
+ ephemeral: bool = MISSING,
file: File = MISSING,
files: List[File] = MISSING,
embed: Embed = MISSING,
@@ -1172,6 +1177,7 @@ class Webhook(BaseWebhook):
username: str = MISSING,
avatar_url: str = MISSING,
tts: bool = False,
+ ephemeral: bool = False,
file: File = MISSING,
files: List[File] = MISSING,
embed: Embed = MISSING,
@@ -1199,7 +1205,8 @@ class Webhook(BaseWebhook):
wait: :class:`bool`
Whether the server should wait before sending a response. This essentially
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`
The username to send with this message. If no username is provided
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.
tts: :class:`bool`
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`
The file to upload. This cannot be mixed with ``files`` parameter.
files: List[:class:`File`]
@@ -1237,7 +1247,8 @@ class Webhook(BaseWebhook):
ValueError
The length of ``embeds`` was invalid.
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
---------
@@ -1252,6 +1263,13 @@ class Webhook(BaseWebhook):
if content is None:
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(
content=content,
username=username,
@@ -1261,6 +1279,7 @@ class Webhook(BaseWebhook):
files=files,
embed=embed,
embeds=embeds,
+ ephemeral=ephemeral,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
)