Skip to content

Commit 2d1d727

Browse files
ToothyDevpre-commit-ci[bot]Paillat-devJustaSqu1d
authored
feat: ✨ silent and supress_embeds parameters for all applicable methods (#3062)
* 📝 Add missing docs to .respond methods * style(pre-commit): auto fixes from pre-commit.com hooks * Add overloads to type method properly (interaction) * Add overloads to type method properly (ApplicationContext) * style(pre-commit): auto fixes from pre-commit.com hooks * Adjust typing and make it a transparent passthrough * style(pre-commit): auto fixes from pre-commit.com hooks * Add typing for args/kwargs * Adjust changelog * 🐛 Make optional params optional * style(pre-commit): auto fixes from pre-commit.com hooks * Update changelog * style(pre-commit): auto fixes from pre-commit.com hooks * ✨ Add new parameters initially * style(pre-commit): auto fixes from pre-commit.com hooks * 📝 Fix up docs a bit * Change overloads * Apply code change requests * Add suppress kwargs where I forgot them * Add missing docs * Make doc text equal * Fix merge request mistakes * Fix bool / poll mistype * Deprecate old parameter and replace it with new one * Update changelog * Apply code change requests * Apply suggestions from code review Co-authored-by: Paillat <jeremiecotti@ik.me> Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> * Fix intendation * oops * Make changelog more wordy but more correct * Apply suggestions from code review Co-authored-by: Paillat <jeremiecotti@ik.me> Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> * style(pre-commit): auto fixes from pre-commit.com hooks * Update changelog as requested * Update changelog as requested 2 * Fix docstring * Update CHANGELOG.md Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Paillat <jeremiecotti@ik.me> * style(pre-commit): auto fixes from pre-commit.com hooks * Adjust changelog per request * Apply suggestion from @Paillat-dev Signed-off-by: Paillat <jeremiecotti@ik.me> * style(pre-commit): auto fixes from pre-commit.com hooks --------- Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> Signed-off-by: Paillat <jeremiecotti@ik.me> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Paillat <jeremiecotti@ik.me> Co-authored-by: Paillat <paillat@pycord.dev> Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
1 parent 4af906e commit 2d1d727

File tree

7 files changed

+135
-12
lines changed

7 files changed

+135
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ These changes are available on the `master` branch, but have not yet been releas
1414

1515
- Added `Member.colours` and `Member.colors` properties.
1616
([#3063](https://github.com/Pycord-Development/pycord/pull/3063))
17+
- Added the ability to respond to interactions with suppressed push and desktop
18+
notifications. ([#3062](https://github.com/Pycord-Development/pycord/pull/3062))
1719

1820
### Changed
1921

@@ -29,6 +31,10 @@ These changes are available on the `master` branch, but have not yet been releas
2931

3032
### Deprecated
3133

34+
- Deprecated the `suppress` parameter in all applicable message-related methods in favor
35+
of `suppress_embeds`.
36+
([#3062](https://github.com/Pycord-Development/pycord/pull/3062))
37+
3238
### Removed
3339

3440
- Removed the guild creation and ownership-related methods and arguments due to updated

discord/abc.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from .role import Role
5656
from .scheduled_events import ScheduledEvent
5757
from .sticker import GuildSticker, StickerItem
58+
from .utils import warn_deprecated
5859
from .voice_client import VoiceClient, VoiceProtocol
5960

6061
__all__ = (
@@ -1358,6 +1359,7 @@ async def send(
13581359
view: BaseView = ...,
13591360
poll: Poll = ...,
13601361
suppress: bool = ...,
1362+
suppress_embeds: bool = ...,
13611363
silent: bool = ...,
13621364
) -> Message: ...
13631365

@@ -1379,6 +1381,7 @@ async def send(
13791381
view: BaseView = ...,
13801382
poll: Poll = ...,
13811383
suppress: bool = ...,
1384+
suppress_embeds: bool = ...,
13821385
silent: bool = ...,
13831386
) -> Message: ...
13841387

@@ -1400,6 +1403,7 @@ async def send(
14001403
view: BaseView = ...,
14011404
poll: Poll = ...,
14021405
suppress: bool = ...,
1406+
suppress_embeds: bool = ...,
14031407
silent: bool = ...,
14041408
) -> Message: ...
14051409

@@ -1421,6 +1425,7 @@ async def send(
14211425
view: BaseView = ...,
14221426
poll: Poll = ...,
14231427
suppress: bool = ...,
1428+
suppress_embeds: bool = ...,
14241429
silent: bool = ...,
14251430
) -> Message: ...
14261431

@@ -1443,6 +1448,7 @@ async def send(
14431448
view=None,
14441449
poll=None,
14451450
suppress=None,
1451+
suppress_embeds=None,
14461452
silent=None,
14471453
):
14481454
"""|coro|
@@ -1521,6 +1527,12 @@ async def send(
15211527
.. versionadded:: 2.0
15221528
suppress: :class:`bool`
15231529
Whether to suppress embeds for the message.
1530+
1531+
.. deprecated:: 2.8
1532+
suppress_embeds: :class:`bool`
1533+
Whether to suppress embeds for the message.
1534+
1535+
.. versionadded:: 2.8
15241536
silent: :class:`bool`
15251537
Whether to suppress push and desktop notifications for the message.
15261538
@@ -1568,8 +1580,13 @@ async def send(
15681580
)
15691581
embeds = [embed.to_dict() for embed in embeds]
15701582

1583+
if suppress is not None:
1584+
warn_deprecated("suppress", "suppress_embeds", "2.8")
1585+
if suppress_embeds is None:
1586+
suppress_embeds = suppress
1587+
15711588
flags = MessageFlags(
1572-
suppress_embeds=bool(suppress),
1589+
suppress_embeds=bool(suppress_embeds),
15731590
suppress_notifications=bool(silent),
15741591
)
15751592

discord/commands/context.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ async def respond(
294294
files: list[File] | None = None,
295295
poll: Poll | None = None,
296296
delete_after: float | None = None,
297+
silent: bool = False,
298+
suppress_embeds: bool = False,
297299
) -> Interaction | WebhookMessage: ...
298300

299301
@overload
@@ -309,6 +311,8 @@ async def respond(
309311
files: list[File] | None = None,
310312
poll: Poll | None = None,
311313
delete_after: float | None = None,
314+
silent: bool = False,
315+
suppress_embeds: bool = False,
312316
) -> Interaction | WebhookMessage: ...
313317

314318
@discord.utils.copy_doc(Interaction.respond)

discord/interactions.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from .object import Object
4848
from .permissions import Permissions
4949
from .user import User
50+
from .utils import warn_deprecated
5051
from .webhook.async_ import (
5152
Webhook,
5253
WebhookMessage,
@@ -525,7 +526,8 @@ async def edit_original_response(
525526
view: BaseView | None = MISSING,
526527
allowed_mentions: AllowedMentions | None = None,
527528
delete_after: float | None = None,
528-
suppress: bool = False,
529+
suppress: bool | None = None,
530+
suppress_embeds: bool = None,
529531
) -> InteractionMessage:
530532
"""|coro|
531533
@@ -567,6 +569,12 @@ async def edit_original_response(
567569
suppress: :class:`bool`
568570
Whether to suppress embeds for the message.
569571
572+
.. deprecated:: 2.8
573+
suppress_embeds: :class:`bool`
574+
Whether to suppress embeds for the message.
575+
576+
.. versionadded:: 2.8
577+
570578
Returns
571579
-------
572580
:class:`InteractionMessage`
@@ -585,6 +593,12 @@ async def edit_original_response(
585593
"""
586594

587595
previous_mentions: AllowedMentions | None = self._state.allowed_mentions
596+
if suppress is not None:
597+
warn_deprecated("suppress", "suppress_embeds", "2.8")
598+
if suppress_embeds is None:
599+
suppress_embeds = suppress
600+
elif suppress_embeds is None:
601+
suppress_embeds = False
588602
params = handle_message_parameters(
589603
content=content,
590604
file=file,
@@ -595,7 +609,7 @@ async def edit_original_response(
595609
view=view,
596610
allowed_mentions=allowed_mentions,
597611
previous_allowed_mentions=previous_mentions,
598-
suppress=suppress,
612+
suppress=suppress_embeds,
599613
)
600614
if view and self.message:
601615
self._state.prevent_view_updates_for(self.message.id)
@@ -712,6 +726,8 @@ async def respond(
712726
files: list[File] | None = None,
713727
poll: Poll | None = None,
714728
delete_after: float | None = None,
729+
silent: bool = False,
730+
suppress_embeds: bool = False,
715731
) -> Interaction | WebhookMessage: ...
716732

717733
@overload
@@ -727,6 +743,8 @@ async def respond(
727743
files: list[File] | None = None,
728744
poll: Poll | None = None,
729745
delete_after: float | None = None,
746+
silent: bool = False,
747+
suppress_embeds: bool = False,
730748
) -> Interaction | WebhookMessage: ...
731749

732750
async def respond(self, *args, **kwargs) -> Interaction | WebhookMessage:
@@ -767,6 +785,14 @@ async def respond(self, *args, **kwargs) -> Interaction | WebhookMessage:
767785
The poll to send.
768786
769787
.. versionadded:: 2.6
788+
silent: :class:`bool`
789+
Whether to suppress push and desktop notifications for the message.
790+
791+
.. versionadded:: 2.8
792+
suppress_embeds: :class:`bool`
793+
Whether to suppress embeds for the message.
794+
795+
.. versionadded:: 2.8
770796
771797
Returns
772798
-------
@@ -1024,6 +1050,8 @@ async def send_message(
10241050
files: list[File] | None = None,
10251051
poll: Poll | None = None,
10261052
delete_after: float | None = None,
1053+
silent: bool = False,
1054+
suppress_embeds: bool = False,
10271055
) -> Interaction:
10281056
"""|coro|
10291057
@@ -1061,6 +1089,14 @@ async def send_message(
10611089
The poll to send.
10621090
10631091
.. versionadded:: 2.6
1092+
silent: :class:`bool`
1093+
Whether to suppress push and desktop notifications for the message.
1094+
1095+
.. versionadded:: 2.8
1096+
suppress_embeds: :class:`bool`
1097+
Whether to suppress embeds for the message.
1098+
1099+
.. versionadded:: 2.8
10641100
10651101
Returns
10661102
-------
@@ -1099,7 +1135,11 @@ async def send_message(
10991135
if content is not None:
11001136
payload["content"] = str(content)
11011137

1102-
flags = MessageFlags(ephemeral=ephemeral)
1138+
flags = MessageFlags(
1139+
ephemeral=ephemeral,
1140+
suppress_notifications=silent,
1141+
suppress_embeds=suppress_embeds,
1142+
)
11031143

11041144
if view:
11051145
payload["components"] = view.to_components()

discord/message.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from .reaction import Reaction
6161
from .sticker import StickerItem
6262
from .threads import Thread
63-
from .utils import MISSING, escape_mentions, find
63+
from .utils import MISSING, escape_mentions, find, warn_deprecated
6464

6565
if TYPE_CHECKING:
6666
from .abc import (
@@ -1737,6 +1737,7 @@ async def edit(
17371737
files: list[File] | None = ...,
17381738
attachments: list[Attachment] = ...,
17391739
suppress: bool = ...,
1740+
suppress_embeds: bool = ...,
17401741
delete_after: float | None = ...,
17411742
allowed_mentions: AllowedMentions | None = ...,
17421743
view: BaseView | None = ...,
@@ -1751,6 +1752,7 @@ async def edit(
17511752
files: list[Sequence[File]] = MISSING,
17521753
attachments: list[Attachment] = MISSING,
17531754
suppress: bool = MISSING,
1755+
suppress_embeds: bool = MISSING,
17541756
delete_after: float | None = None,
17551757
allowed_mentions: AllowedMentions | None = MISSING,
17561758
view: BaseView | None = MISSING,
@@ -1789,6 +1791,15 @@ async def edit(
17891791
all the embeds if set to ``True``. If set to ``False``
17901792
this brings the embeds back if they were suppressed.
17911793
Using this parameter requires :attr:`~.Permissions.manage_messages`.
1794+
1795+
.. deprecated:: 2.8
1796+
suppress_embeds: :class:`bool`
1797+
Whether to suppress embeds for the message. This removes
1798+
all the embeds if set to ``True``. If set to ``False``
1799+
this brings the embeds back if they were suppressed.
1800+
Using this parameter requires :attr:`~.Permissions.manage_messages`.
1801+
1802+
.. versionadded:: 2.8
17921803
delete_after: Optional[:class:`float`]
17931804
If provided, the number of seconds to wait in the background
17941805
before deleting the message we just edited. If the deletion fails,
@@ -1837,7 +1848,12 @@ async def edit(
18371848
flags = MessageFlags._from_value(self.flags.value)
18381849

18391850
if suppress is not MISSING:
1840-
flags.suppress_embeds = suppress
1851+
warn_deprecated("suppress", "suppress_embeds", "2.8")
1852+
if suppress_embeds is MISSING:
1853+
suppress_embeds = suppress
1854+
1855+
if suppress_embeds is not MISSING:
1856+
flags.suppress_embeds = suppress_embeds
18411857

18421858
if allowed_mentions is MISSING:
18431859
if (

discord/webhook/async_.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"PartialWebhookGuild",
6464
)
6565

66+
from ..utils import warn_deprecated
67+
6668
_log = logging.getLogger(__name__)
6769

6870
if TYPE_CHECKING:
@@ -646,8 +648,10 @@ def handle_message_parameters(
646648
applied_tags: list[Snowflake] = MISSING,
647649
allowed_mentions: AllowedMentions | None = MISSING,
648650
previous_allowed_mentions: AllowedMentions | None = None,
649-
suppress: bool = False,
651+
suppress: bool | None = None,
650652
thread_name: str | None = None,
653+
suppress_embeds: bool = None,
654+
silent: bool = False,
651655
) -> ExecuteWebhookParameters:
652656
if files is not MISSING and file is not MISSING:
653657
raise TypeError("Cannot mix file and files keyword arguments.")
@@ -667,10 +671,16 @@ def handle_message_parameters(
667671
_attachments = []
668672
if attachments is not MISSING:
669673
_attachments = [a.to_dict() for a in attachments]
670-
674+
if suppress is not None:
675+
warn_deprecated("suppress", "suppress_embeds", "2.8")
676+
if suppress_embeds is None:
677+
suppress_embeds = suppress
678+
elif suppress_embeds is None:
679+
suppress_embeds = False
671680
flags = MessageFlags(
672-
suppress_embeds=suppress,
681+
suppress_embeds=suppress_embeds,
673682
ephemeral=ephemeral,
683+
suppress_notifications=silent,
674684
)
675685

676686
if view is not MISSING:
@@ -1661,6 +1671,8 @@ async def send(
16611671
applied_tags: list[Snowflake] = MISSING,
16621672
wait: Literal[True],
16631673
delete_after: float = None,
1674+
silent: bool = False,
1675+
suppress_embeds: bool = False,
16641676
) -> WebhookMessage: ...
16651677

16661678
@overload
@@ -1684,6 +1696,8 @@ async def send(
16841696
applied_tags: list[Snowflake] = MISSING,
16851697
wait: Literal[False] = ...,
16861698
delete_after: float = None,
1699+
silent: bool = False,
1700+
suppress_embeds: bool = False,
16871701
) -> None: ...
16881702

16891703
async def send(
@@ -1706,6 +1720,8 @@ async def send(
17061720
applied_tags: list[Snowflake] = MISSING,
17071721
wait: bool = False,
17081722
delete_after: float = None,
1723+
silent: bool = False,
1724+
suppress_embeds: bool = False,
17091725
) -> WebhookMessage | None:
17101726
"""|coro|
17111727
@@ -1786,6 +1802,14 @@ async def send(
17861802
The poll to send.
17871803
17881804
.. versionadded:: 2.6
1805+
silent: :class:`bool`
1806+
Whether to suppress push and desktop notifications for the message.
1807+
1808+
.. versionadded:: 2.8
1809+
suppress_embeds: :class:`bool`
1810+
Whether to suppress embeds for the message.
1811+
1812+
.. versionadded:: 2.8
17891813
17901814
Returns
17911815
-------
@@ -1872,6 +1896,8 @@ async def send(
18721896
allowed_mentions=allowed_mentions,
18731897
previous_allowed_mentions=previous_mentions,
18741898
thread_name=thread_name,
1899+
silent=silent,
1900+
suppress=suppress_embeds,
18751901
)
18761902
adapter = async_context.get()
18771903
thread_id: int | None = None

0 commit comments

Comments
 (0)