Skip to content

Commit 50ff7ea

Browse files
committed
add support for flags
1 parent f066a04 commit 50ff7ea

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ pip install discord-webhook
1818
* [Basic Webhook](#basic-webhook)
1919
* [Create Multiple Instances / Use multiple URLs](#create-multiple-instances)
2020
* [Get Webhook by ID](#get-webhook-by-id)
21-
* [Send Webhook to thread](#send-webhook-to-thread)
21+
* [Send Webhook to a thread](#send-webhook-to-a-thread)
2222
* [Manage Being Rate Limited](#manage-being-rate-limited)
2323
* [Embedded Content](#webhook-with-embedded-content)
2424
* [Edit Webhook Message](#edit-webhook-messages)
2525
* [Delete Webhook Message](#delete-webhook-messages)
2626
* [Send Files](#send-files)
2727
* [Remove Embeds and Files](#remove-embeds-and-files)
2828
* [Allowed Mentions](#allowed-mentions)
29+
* [Use Message Flags](#use-message-flags)
2930
* [Use Proxies](#use-proxies)
3031
* [Timeout](#timeout)
3132
* [Async Support](#async-support)
@@ -62,7 +63,7 @@ webhook = DiscordWebhook(url="your webhook url", id="your webhook message id")
6263
# now you could delete or edit the webhook
6364
# ...
6465
````
65-
### Send Webhook to thread
66+
### Send Webhook to a thread
6667
You can send a message to an existing thread by setting `thread_id` or create a new thread in a forum channel by using a `thread_name`.
6768
```python
6869
from discord_webhook import DiscordWebhook
@@ -294,7 +295,7 @@ response = webhook.execute()
294295

295296
### Allowed Mentions
296297

297-
Look into the [Discord Docs](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for examples and for more explanation
298+
Look into the [Discord Docs](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for examples and for more explanation.
298299

299300
This example would only ping user `123` and `124` but not everyone else.
300301

@@ -311,6 +312,28 @@ webhook = DiscordWebhook(url="your webhook url", content=content, allowed_mentio
311312
response = webhook.execute()
312313
```
313314

315+
### Use Message Flags
316+
317+
Flags can also be set for messages. Only two are currently supported.
318+
319+
```python
320+
from discord_webhook import DiscordEmbed, DiscordWebhook
321+
from discord_webhook.constants import MessageFlags
322+
323+
content = "Hi."
324+
325+
# this message will not trigger push and desktop notifications
326+
webhook = DiscordWebhook(url="your webhook url", content=content, flags=MessageFlags.SUPPRESS_NOTIFICATIONS.value)
327+
response = webhook.execute()
328+
329+
# do not include any embeds when serializing this message
330+
webhook = DiscordWebhook(url="your webhook url", content=content, flags=MessageFlags.SUPPRESS_EMBEDS.value)
331+
embed = DiscordEmbed(title="Your Title", description="Lorem ipsum dolor sit", color="03b2f8")
332+
webhook.add_embed(embed)
333+
# even if an embed has been added, it will not appear in the message.
334+
response = webhook.execute()
335+
```
336+
314337
### Use Proxies
315338

316339
```python

discord_webhook/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from enum import Enum
2+
3+
4+
class MessageFlags(Enum):
5+
NONE = 0
6+
SUPPRESS_EMBEDS = 4
7+
SUPPRESS_NOTIFICATIONS = 4096

discord_webhook/webhook.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def __init__(self, url: str, **kwargs) -> None:
250250
:keyword str avatar_url: override the default avatar of the webhook
251251
:keyword str content: the message contents
252252
:keyword list embeds: list of embedded rich content
253+
:keyword int flags: apply flags to the message
253254
:keyword dict files: to apply file(s) with message
254255
:keyword str id: webhook id
255256
:keyword dict proxies: proxies that should be used
@@ -266,13 +267,13 @@ def __init__(self, url: str, **kwargs) -> None:
266267
self.avatar_url = kwargs.get("avatar_url")
267268
self.content = kwargs.get("content")
268269
self.embeds = kwargs.get("embeds", [])
270+
self.flags = kwargs.get("flags")
269271
self.files = kwargs.get("files", {})
270272
self.id = kwargs.get("id")
271273
self.proxies = kwargs.get("proxies")
272274
self.rate_limit_retry = kwargs.get("rate_limit_retry", False)
273275
self.thread_id = kwargs.get("thread_id")
274276
self.thread_name = kwargs.get("thread_name")
275-
self.thread_name = kwargs.get("thread_name")
276277
self.timeout = kwargs.get("timeout")
277278
self.tts = kwargs.get("tts", False)
278279
self.url = url
@@ -361,6 +362,13 @@ def set_content(self, content: str) -> None:
361362
"""
362363
self.content = content
363364

365+
def set_flags(self, flags: int) -> None:
366+
"""
367+
Set the flags of the webhook.
368+
:param int flags: flags as integer
369+
"""
370+
self.flags = flags
371+
364372
@property
365373
def json(self) -> Dict[str, Any]:
366374
"""

0 commit comments

Comments
 (0)