diff --git a/CHANGELOG.md b/CHANGELOG.md index 8210bcb658..d03dca3a40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,14 @@ These changes are available on the `master` branch, but have not yet been releas - Added `.extension` attribute to the `AppEmoji` and `GuildEmoji` classes. ([#3055](https://github.com/Pycord-Development/pycord/pull/3055)) +- Added `silent` parameter to all methods that send messages, including + `ApplicationContext.respond`, `Interaction.respond` and + `InteractionResponse.send_message`. + ([#3062](https://github.com/Pycord-Development/pycord/pull/3062)) +- Added `suppress_embeds` parameter to all methods that send messages, replacing + `suppress`, including `ApplicationContext.respond`, `Interaction.respond` and + `InteractionResponse.send_message`. + ([#3062](https://github.com/Pycord-Development/pycord/pull/3062)) ### Changed @@ -43,6 +51,12 @@ These changes are available on the `master` branch, but have not yet been releas method were not type-hinted as optional. ([#3061](https://github.com/Pycord-Development/pycord/pull/3061)) +### Deprecated + +- Deprecated the `suppress` parameter in all applicable message-related methods. Does + not affect any functions related to voice. + ([#3062](https://github.com/Pycord-Development/pycord/pull/3062)) + ### Removed - Removed the guild creation and ownership-related methods and arguments due to updated diff --git a/discord/abc.py b/discord/abc.py index 8185154475..e9e8ea7cd9 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -55,6 +55,7 @@ from .role import Role from .scheduled_events import ScheduledEvent from .sticker import GuildSticker, StickerItem +from .utils import warn_deprecated from .voice_client import VoiceClient, VoiceProtocol __all__ = ( @@ -1358,6 +1359,7 @@ async def send( view: BaseView = ..., poll: Poll = ..., suppress: bool = ..., + suppress_embeds: bool = ..., silent: bool = ..., ) -> Message: ... @@ -1379,6 +1381,7 @@ async def send( view: BaseView = ..., poll: Poll = ..., suppress: bool = ..., + suppress_embeds: bool = ..., silent: bool = ..., ) -> Message: ... @@ -1400,6 +1403,7 @@ async def send( view: BaseView = ..., poll: Poll = ..., suppress: bool = ..., + suppress_embeds: bool = ..., silent: bool = ..., ) -> Message: ... @@ -1421,6 +1425,7 @@ async def send( view: BaseView = ..., poll: Poll = ..., suppress: bool = ..., + suppress_embeds: bool = ..., silent: bool = ..., ) -> Message: ... @@ -1443,6 +1448,7 @@ async def send( view=None, poll=None, suppress=None, + suppress_embeds=None, silent=None, ): """|coro| @@ -1521,6 +1527,12 @@ async def send( .. versionadded:: 2.0 suppress: :class:`bool` Whether to suppress embeds for the message. + + .. deprecated:: 2.8 + suppress_embeds: :class:`bool` + Whether to suppress embeds for the message. + + .. versionadded:: 2.8 silent: :class:`bool` Whether to suppress push and desktop notifications for the message. @@ -1568,8 +1580,13 @@ async def send( ) embeds = [embed.to_dict() for embed in embeds] + if suppress is not None: + warn_deprecated("suppress", "suppress_embeds", "2.8") + if suppress_embeds is None: + suppress_embeds = suppress + flags = MessageFlags( - suppress_embeds=bool(suppress), + suppress_embeds=bool(suppress_embeds), suppress_notifications=bool(silent), ) diff --git a/discord/commands/context.py b/discord/commands/context.py index b9d6f8eff0..c815229ca8 100644 --- a/discord/commands/context.py +++ b/discord/commands/context.py @@ -294,6 +294,8 @@ async def respond( files: list[File] | None = None, poll: Poll | None = None, delete_after: float | None = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> Interaction | WebhookMessage: ... @overload @@ -309,6 +311,8 @@ async def respond( files: list[File] | None = None, poll: Poll | None = None, delete_after: float | None = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> Interaction | WebhookMessage: ... @discord.utils.copy_doc(Interaction.respond) diff --git a/discord/interactions.py b/discord/interactions.py index 3578ca2f09..ceff153b14 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -47,6 +47,7 @@ from .object import Object from .permissions import Permissions from .user import User +from .utils import warn_deprecated from .webhook.async_ import ( Webhook, WebhookMessage, @@ -525,7 +526,8 @@ async def edit_original_response( view: BaseView | None = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, - suppress: bool = False, + suppress: bool | None = None, + suppress_embeds: bool = None, ) -> InteractionMessage: """|coro| @@ -567,6 +569,12 @@ async def edit_original_response( suppress: :class:`bool` Whether to suppress embeds for the message. + .. deprecated:: 2.8 + suppress_embeds: :class:`bool` + Whether to suppress embeds for the message. + + .. versionadded:: 2.8 + Returns ------- :class:`InteractionMessage` @@ -585,6 +593,12 @@ async def edit_original_response( """ previous_mentions: AllowedMentions | None = self._state.allowed_mentions + if suppress is not None: + warn_deprecated("suppress", "suppress_embeds", "2.8") + if suppress_embeds is None: + suppress_embeds = suppress + elif suppress_embeds is None: + suppress_embeds = False params = handle_message_parameters( content=content, file=file, @@ -595,7 +609,7 @@ async def edit_original_response( view=view, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, - suppress=suppress, + suppress=suppress_embeds, ) if view and self.message: self._state.prevent_view_updates_for(self.message.id) @@ -712,6 +726,8 @@ async def respond( files: list[File] | None = None, poll: Poll | None = None, delete_after: float | None = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> Interaction | WebhookMessage: ... @overload @@ -727,6 +743,8 @@ async def respond( files: list[File] | None = None, poll: Poll | None = None, delete_after: float | None = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> Interaction | WebhookMessage: ... async def respond(self, *args, **kwargs) -> Interaction | WebhookMessage: @@ -767,6 +785,14 @@ async def respond(self, *args, **kwargs) -> Interaction | WebhookMessage: The poll to send. .. versionadded:: 2.6 + silent: :class:`bool` + Whether to suppress push and desktop notifications for the message. + + .. versionadded:: 2.8 + suppress_embeds: :class:`bool` + Whether to suppress embeds for the message. + + .. versionadded:: 2.8 Returns ------- @@ -1024,6 +1050,8 @@ async def send_message( files: list[File] | None = None, poll: Poll | None = None, delete_after: float | None = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> Interaction: """|coro| @@ -1061,6 +1089,14 @@ async def send_message( The poll to send. .. versionadded:: 2.6 + silent: :class:`bool` + Whether to suppress push and desktop notifications for the message. + + .. versionadded:: 2.8 + suppress_embeds: :class:`bool` + Whether to suppress embeds for the message. + + .. versionadded:: 2.8 Returns ------- @@ -1099,7 +1135,11 @@ async def send_message( if content is not None: payload["content"] = str(content) - flags = MessageFlags(ephemeral=ephemeral) + flags = MessageFlags( + ephemeral=ephemeral, + suppress_notifications=silent, + suppress_embeds=suppress_embeds, + ) if view: payload["components"] = view.to_components() diff --git a/discord/message.py b/discord/message.py index b59d78c89a..5f6ae277a0 100644 --- a/discord/message.py +++ b/discord/message.py @@ -60,7 +60,7 @@ from .reaction import Reaction from .sticker import StickerItem from .threads import Thread -from .utils import MISSING, escape_mentions, find +from .utils import MISSING, escape_mentions, find, warn_deprecated if TYPE_CHECKING: from .abc import ( @@ -1737,6 +1737,7 @@ async def edit( files: list[File] | None = ..., attachments: list[Attachment] = ..., suppress: bool = ..., + suppress_embeds: bool = ..., delete_after: float | None = ..., allowed_mentions: AllowedMentions | None = ..., view: BaseView | None = ..., @@ -1751,6 +1752,7 @@ async def edit( files: list[Sequence[File]] = MISSING, attachments: list[Attachment] = MISSING, suppress: bool = MISSING, + suppress_embeds: bool = MISSING, delete_after: float | None = None, allowed_mentions: AllowedMentions | None = MISSING, view: BaseView | None = MISSING, @@ -1789,6 +1791,15 @@ async def edit( all the embeds if set to ``True``. If set to ``False`` this brings the embeds back if they were suppressed. Using this parameter requires :attr:`~.Permissions.manage_messages`. + + .. deprecated: 2.8 + suppress_embeds: :class:`bool` + Whether to suppress embeds for the message. This removes + all the embeds if set to ``True``. If set to ``False`` + this brings the embeds back if they were suppressed. + Using this parameter requires :attr:`~.Permissions.manage_messages`. + + .. versionadded:: 2.8 delete_after: Optional[:class:`float`] If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, @@ -1837,7 +1848,12 @@ async def edit( flags = MessageFlags._from_value(self.flags.value) if suppress is not MISSING: - flags.suppress_embeds = suppress + warn_deprecated("suppress", "suppress_embeds", "2.8") + if suppress_embeds is MISSING: + suppress_embeds = suppress + + if suppress_embeds is not MISSING: + flags.suppress_embeds = suppress_embeds if allowed_mentions is MISSING: if ( diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index c9093f7781..d7f9260289 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -63,6 +63,8 @@ "PartialWebhookGuild", ) +from ..utils import warn_deprecated + _log = logging.getLogger(__name__) if TYPE_CHECKING: @@ -646,8 +648,10 @@ def handle_message_parameters( applied_tags: list[Snowflake] = MISSING, allowed_mentions: AllowedMentions | None = MISSING, previous_allowed_mentions: AllowedMentions | None = None, - suppress: bool = False, + suppress: bool | None = None, thread_name: str | None = None, + suppress_embeds: bool = None, + silent: bool = False, ) -> ExecuteWebhookParameters: if files is not MISSING and file is not MISSING: raise TypeError("Cannot mix file and files keyword arguments.") @@ -667,10 +671,16 @@ def handle_message_parameters( _attachments = [] if attachments is not MISSING: _attachments = [a.to_dict() for a in attachments] - + if suppress is not None: + warn_deprecated("suppress", "suppress_embeds", "2.8") + if suppress_embeds is None: + suppress_embeds = suppress + elif suppress_embeds is None: + suppress_embeds = False flags = MessageFlags( - suppress_embeds=suppress, + suppress_embeds=suppress_embeds, ephemeral=ephemeral, + suppress_notifications=silent, ) if view is not MISSING: @@ -1661,6 +1671,8 @@ async def send( applied_tags: list[Snowflake] = MISSING, wait: Literal[True], delete_after: float = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> WebhookMessage: ... @overload @@ -1684,6 +1696,8 @@ async def send( applied_tags: list[Snowflake] = MISSING, wait: Literal[False] = ..., delete_after: float = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> None: ... async def send( @@ -1706,6 +1720,8 @@ async def send( applied_tags: list[Snowflake] = MISSING, wait: bool = False, delete_after: float = None, + silent: bool = False, + suppress_embeds: bool = False, ) -> WebhookMessage | None: """|coro| @@ -1786,6 +1802,14 @@ async def send( The poll to send. .. versionadded:: 2.6 + silent: :class:`bool` + Whether to suppress push and desktop notifications for the message. + + .. versionadded:: 2.8 + suppress_embeds: :class:`bool` + Whether to suppress embeds for the message. + + .. versionadded:: 2.8 Returns ------- @@ -1872,6 +1896,8 @@ async def send( allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, thread_name=thread_name, + silent=silent, + suppress=suppress_embeds, ) adapter = async_context.get() thread_id: int | None = None diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index fde7031321..99b142e0bf 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -60,6 +60,8 @@ "SyncWebhookMessage", ) +from ..utils import warn_deprecated + _log = logging.getLogger(__name__) if TYPE_CHECKING: @@ -469,6 +471,7 @@ def edit( files: list[File] = MISSING, allowed_mentions: AllowedMentions | None = None, suppress: bool | None = MISSING, + suppress_embeds: bool | None = MISSING, ) -> SyncWebhookMessage: """Edits the message. @@ -492,6 +495,12 @@ def edit( suppress: Optional[:class:`bool`] Whether to suppress embeds for the message. + .. deprecated:: 2.8 + suppress_embeds: Optional[:class:`bool`] + Whether to suppress embeds for the message. + + .. versionadded:: 2.8 + Returns ------- :class:`SyncWebhookMessage` @@ -516,8 +525,13 @@ def edit( elif isinstance(self.channel, Thread): thread = Object(self.channel.id) - if suppress is MISSING: - suppress = self.flags.suppress_embeds + if suppress is not MISSING: + warn_deprecated("suppress", "suppress_embeds", "2.8") + if suppress_embeds is MISSING: + suppress_embeds = suppress + + if suppress_embeds is MISSING: + suppress_embeds = self.flags.suppress_embeds return self._state._webhook.edit_message( self.id, @@ -528,7 +542,7 @@ def edit( files=files, allowed_mentions=allowed_mentions, thread=thread, - suppress=suppress, + suppress=suppress_embeds, ) def delete(self, *, delay: float | None = None) -> None: