Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit db58e62

Browse files
committed
Allow Webhook.send to send ephemeral messages
This is only available for application webhooks
1 parent 267fad9 commit db58e62

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

discord/webhook/async_.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ def handle_message_parameters(
418418
username: str = MISSING,
419419
avatar_url: str = MISSING,
420420
tts: bool = False,
421+
ephemeral: bool = False,
421422
file: File = MISSING,
422423
files: List[File] = MISSING,
423424
embed: Optional[Embed] = MISSING,
@@ -453,6 +454,8 @@ def handle_message_parameters(
453454
payload['avatar_url'] = str(avatar_url)
454455
if username:
455456
payload['username'] = username
457+
if ephemeral:
458+
payload['flags'] = 64
456459

457460
if allowed_mentions:
458461
if previous_allowed_mentions is not None:
@@ -1139,6 +1142,7 @@ async def send(
11391142
username: str = MISSING,
11401143
avatar_url: str = MISSING,
11411144
tts: bool = MISSING,
1145+
ephemeral: bool = MISSING,
11421146
file: File = MISSING,
11431147
files: List[File] = MISSING,
11441148
embed: Embed = MISSING,
@@ -1156,6 +1160,7 @@ async def send(
11561160
username: str = MISSING,
11571161
avatar_url: str = MISSING,
11581162
tts: bool = MISSING,
1163+
ephemeral: bool = MISSING,
11591164
file: File = MISSING,
11601165
files: List[File] = MISSING,
11611166
embed: Embed = MISSING,
@@ -1172,6 +1177,7 @@ async def send(
11721177
username: str = MISSING,
11731178
avatar_url: str = MISSING,
11741179
tts: bool = False,
1180+
ephemeral: bool = False,
11751181
file: File = MISSING,
11761182
files: List[File] = MISSING,
11771183
embed: Embed = MISSING,
@@ -1199,7 +1205,8 @@ async def send(
11991205
wait: :class:`bool`
12001206
Whether the server should wait before sending a response. This essentially
12011207
means that the return type of this function changes from ``None`` to
1202-
a :class:`WebhookMessage` if set to ``True``.
1208+
a :class:`WebhookMessage` if set to ``True``. If the type of webhook
1209+
is :attr:`WebhookType.application` then this is always set to ``True``.
12031210
username: :class:`str`
12041211
The username to send with this message. If no username is provided
12051212
then the default username for the webhook is used.
@@ -1208,6 +1215,9 @@ async def send(
12081215
then the default avatar for the webhook is used.
12091216
tts: :class:`bool`
12101217
Indicates if the message should be sent using text-to-speech.
1218+
ephemeral: :class:`bool`
1219+
Indicates if the message should only be visible to the user.
1220+
This is only available to :attr:`WebhookType.application` webhooks.
12111221
file: :class:`File`
12121222
The file to upload. This cannot be mixed with ``files`` parameter.
12131223
files: List[:class:`File`]
@@ -1237,7 +1247,8 @@ async def send(
12371247
ValueError
12381248
The length of ``embeds`` was invalid.
12391249
InvalidArgument
1240-
There was no token associated with this webhook.
1250+
There was no token associated with this webhook or ``ephemeral``
1251+
was passed with the improper webhook type.
12411252
12421253
Returns
12431254
---------
@@ -1252,6 +1263,13 @@ async def send(
12521263
if content is None:
12531264
content = MISSING
12541265

1266+
application_webhook = self.type is WebhookType.application
1267+
if ephemeral and not application_webhook:
1268+
raise InvalidArgument('ephemeral messages can only be sent from application webhooks')
1269+
1270+
if application_webhook:
1271+
wait = True
1272+
12551273
params = handle_message_parameters(
12561274
content=content,
12571275
username=username,
@@ -1261,6 +1279,7 @@ async def send(
12611279
files=files,
12621280
embed=embed,
12631281
embeds=embeds,
1282+
ephemeral=ephemeral,
12641283
allowed_mentions=allowed_mentions,
12651284
previous_allowed_mentions=previous_mentions,
12661285
)

0 commit comments

Comments
 (0)