Skip to content

Commit adfe2a0

Browse files
committed
feat!: Rename suppress parameter to suppress_embeds everywhere and add suppress_notifications parameter.
1 parent 07c9f23 commit adfe2a0

File tree

7 files changed

+365
-253
lines changed

7 files changed

+365
-253
lines changed

discord/abc.py

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
from __future__ import annotations
2727

2828
import abc
29-
import sys
30-
import copy
3129
import asyncio
32-
30+
import copy
31+
import sys
3332
from typing import (
3433
Any,
3534
List,
@@ -40,21 +39,21 @@
4039
TYPE_CHECKING
4140
)
4241

43-
from .iterators import HistoryIterator
42+
from . import utils
4443
from .context_managers import Typing
45-
from .enums import try_enum, ChannelType, PermissionType
46-
from .errors import InvalidArgument, ClientException
44+
from .enums import ChannelType, PermissionType, try_enum
45+
from .errors import ClientException, InvalidArgument
46+
from .file import File
47+
from .http import handle_message_parameters
48+
from .invite import Invite
49+
from .iterators import HistoryIterator
4750
from .mentions import AllowedMentions
4851
from .permissions import PermissionOverwrite, Permissions
4952
from .role import Role
50-
from .invite import Invite
51-
from .file import File
5253
from .voice_client import VoiceClient, VoiceProtocol
53-
from .http import handle_message_parameters
54-
from . import utils
5554

5655
if TYPE_CHECKING:
57-
import datetime
56+
from datetime import datetime
5857
from .embeds import Embed
5958
from .sticker import GuildSticker
6059
from .components import ActionRow, Button, BaseSelect
@@ -984,23 +983,25 @@ class Messageable(metaclass=abc.ABCMeta):
984983
async def _get_channel(self):
985984
raise NotImplementedError
986985

987-
async def send(self,
988-
content: Any = None,
989-
*,
990-
tts: bool = False,
991-
embed: Optional[Embed] = None,
992-
embeds: Optional[List[Embed]] = None,
993-
components: Optional[List[Union[ActionRow, List[Union[Button, BaseSelect]]]]] = None,
994-
file: Optional[File] = None,
995-
files: Optional[List[File]] = None,
996-
stickers: Optional[List[GuildSticker]] = None,
997-
delete_after: Optional[float] = None,
998-
nonce: Optional[int] = None,
999-
allowed_mentions: Optional[AllowedMentions] = None,
1000-
reference: Optional[Union[Message, MessageReference]] = None,
1001-
mention_author: Optional[bool] = None,
1002-
supress_embeds: Optional[bool] = False
1003-
) -> Message:
986+
async def send(
987+
self,
988+
content: Any = None,
989+
*,
990+
tts: bool = False,
991+
embed: Optional[Embed] = None,
992+
embeds: Optional[List[Embed]] = None,
993+
components: Optional[List[Union[ActionRow, List[Union[Button, BaseSelect]]]]] = None,
994+
file: Optional[File] = None,
995+
files: Optional[List[File]] = None,
996+
stickers: Optional[List[GuildSticker]] = None,
997+
delete_after: Optional[float] = None,
998+
nonce: Optional[int] = None,
999+
allowed_mentions: Optional[AllowedMentions] = None,
1000+
reference: Optional[Union[Message, MessageReference]] = None,
1001+
mention_author: Optional[bool] = None,
1002+
suppress_embeds: bool = False,
1003+
suppress_notifications: bool = False
1004+
) -> Message:
10041005
"""|coro|
10051006
10061007
Sends a message to the destination with the content given.
@@ -1065,9 +1066,16 @@ async def send(self,
10651066
10661067
.. versionadded:: 1.6
10671068
1068-
supress_embeds: Optional[:class:`bool`
1069+
suppress_embeds: :class:`bool`
10691070
Whether to supress embeds send with the message, default to :obj:`False`
1070-
1071+
1072+
suppress_notifications: :class:`bool`
1073+
Whether to suppress desktop- & push-notifications for this message, default to :obj:`False`
1074+
1075+
Users will still see a ping-symbol when they are mentioned in the message, or the message is in a dm channel.
1076+
1077+
.. versionadded:: 2.0
1078+
10711079
Raises
10721080
--------
10731081
~discord.HTTPException
@@ -1104,9 +1112,10 @@ async def send(self,
11041112
else:
11051113
reference = MISSING
11061114

1107-
if supress_embeds:
1115+
if suppress_embeds or suppress_notifications:
11081116
from .flags import MessageFlags
11091117
flags = MessageFlags._from_value(4)
1118+
flags.suppress_notifications = suppress_notifications
11101119
else:
11111120
flags = MISSING
11121121

@@ -1220,13 +1229,15 @@ async def pins(self):
12201229
data = await state.http.pins_from(channel.id)
12211230
return [state.create_message(channel=channel, data=m) for m in data]
12221231

1223-
def history(self,
1224-
*,
1225-
limit: Optional[int] = 100,
1226-
before: Optional[Union[Snowflake, 'datetime.datetime']] = None,
1227-
after: Optional[Union[Snowflake, 'datetime.datetime']] = None,
1228-
around: Optional[Union[Snowflake, 'datetime.datetime']] = None,
1229-
oldest_first: Optional[bool] = None):
1232+
def history(
1233+
self,
1234+
*,
1235+
limit: Optional[int] = 100,
1236+
before: Optional[Union[Snowflake, datetime]] = None,
1237+
after: Optional[Union[Snowflake, datetime]] = None,
1238+
around: Optional[Union[Snowflake, datetime]] = None,
1239+
oldest_first: Optional[bool] = None
1240+
):
12301241
"""Returns an :class:`~discord.AsyncIterator` that enables receiving the destination's message history.
12311242
12321243
You must have :attr:`~Permissions.read_message_history` permissions to use this.
@@ -1264,7 +1275,7 @@ def history(self,
12641275
Retrieve messages around this date or message.
12651276
If a date is provided it must be a timezone-naive datetime representing UTC time.
12661277
When using this argument, the maximum limit is 101. Note that if the limit is an
1267-
even number then this will return at most limit + 1 messages.
1278+
even number, then this will return at most limit + 1 messages.
12681279
oldest_first: Optional[:class:`bool`]
12691280
If set to ``True``, return messages in oldest->newest order. Defaults to ``True`` if
12701281
``after`` is specified, otherwise ``False``.

discord/application_commands.py

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -85,43 +85,32 @@ class Localizations:
8585
"""
8686
Represents a :class:`dict` with localized values.
8787
These are used for application-commands, options and choices ``name_localizations`` and ``description_localizations``
88-
89-
+--------+-------------------------+---------------------+
90-
| Locale | Language Name | Native Name |
91-
| | (lowercase also usable) | |
92-
+========+=========================+=====================+
93-
| da | Danish | Dansk |
94-
| de | German | Deutsch |
95-
| en_GB | English, UK | English, UK |
96-
| en_US | English, US | English, US |
97-
| es_ES | Spanish | Español |
98-
| fr | French | Français |
99-
| hr | Croatian | Hrvatski |
100-
| it | Italian | Italiano |
101-
| lt | Lithuanian | Lietuviškai |
102-
| hu | Hungarian | Magyar |
103-
| nl | Dutch | Nederlands |
104-
| no | Norwegian | Norsk |
105-
| pl | Polish | Polski |
106-
| pt_BR | Portuguese/Brazilian | Português do Brasil |
107-
| ro | Romanian, Romania | Română |
108-
| fi | Finnish | Suomi |
109-
| sv_SE | Swedish | Svenska |
110-
| vi | Vietnamese | Tiếng Việt |
111-
| tr | Turkish | Türkçe |
112-
| cs | Czech | Čeština |
113-
| el | Greek | Ελληνικά |
114-
| bg | Bulgarian | български |
115-
| ru | Russian | Pусский |
116-
| uk | Ukrainian | Українська |
117-
| hi | Hindi | हिन्दी |
118-
| th | Thai | ไทย |
119-
| zh_CN | Chinese, China | 中文 |
120-
| ja | Japanese | 日本語 |
121-
| zh_TW | Chinese, Taiwan | 繁體中文 |
122-
| ko | Korean | 한국어 |
123-
+--------+-------------------------+---------------------+
124-
88+
89+
See :class:`~discord.Locale` for a list of available locals.
90+
91+
Example
92+
-------
93+
94+
.. code-block:: python3
95+
96+
Localizations(
97+
en_US='Hello World!',
98+
de='Hallo Welt!',
99+
fr='Bonjour le monde!'
100+
uk='Привіт світ!'
101+
)
102+
103+
Using the full language name is also possible.
104+
105+
.. code-block:: python3
106+
107+
Localizations(
108+
english_us='Hello World!',
109+
german='Hallo Welt!',
110+
french='Bonjour le monde!'
111+
ukrainian='Привіт світ!'
112+
)
113+
125114
Parameters
126115
----------
127116
kwargs: Any

discord/channel.py

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,33 @@
2525
"""
2626
from __future__ import annotations
2727

28+
import asyncio
2829
import datetime
2930
import time
30-
import asyncio
31-
3231
from typing import (
33-
TYPE_CHECKING,
32+
Any,
3433
Callable,
35-
Union,
36-
Optional,
37-
Sequence,
3834
Coroutine,
35+
Dict,
3936
List,
37+
Optional,
38+
Sequence,
4039
Tuple,
41-
Dict,
42-
Any
40+
TYPE_CHECKING,
41+
Union
4342
)
4443

45-
from .permissions import Permissions, PermissionOverwrite
46-
from .enums import ChannelType, VoiceRegion, AutoArchiveDuration, PostSortOrder, try_enum
47-
from .components import Button, SelectMenu, ActionRow
48-
from .iterators import ThreadMemberIterator
49-
from .mixins import Hashable
50-
from . import utils, abc
51-
from .flags import ChannelFlags
44+
from . import abc, utils
5245
from .asset import Asset
53-
from .errors import ClientException, NoMoreItems, InvalidArgument, ThreadIsArchived
46+
from .components import ActionRow, BaseSelect, Button
47+
from .enums import AutoArchiveDuration, ChannelType, PostSortOrder, try_enum, VoiceRegion
48+
from .errors import ClientException, InvalidArgument, NoMoreItems, ThreadIsArchived
49+
from .flags import ChannelFlags, MessageFlags
5450
from .http import handle_message_parameters
51+
from .iterators import ThreadMemberIterator
52+
from .mixins import Hashable
5553
from .partial_emoji import PartialEmoji
54+
from .permissions import PermissionOverwrite, Permissions
5655

5756
if TYPE_CHECKING:
5857
from .state import ConnectionState
@@ -1072,7 +1071,7 @@ async def remove_member(self, member: Union[Member, int]):
10721071

10731072
return await self._state.http.remove_thread_member(channel_id=self.id, member_id=member_id)
10741073

1075-
async def fetch_members(
1074+
def fetch_members(
10761075
self,
10771076
limit: int = 100,
10781077
after: Union[abc.Snowflake, datetime.datetime] = None,
@@ -1081,36 +1080,42 @@ async def fetch_members(
10811080
"""Returns a :class:`ThreadMemberIterator` that allows to retrieve the currently joined members of this thread.
10821081
10831082
.. note::
1084-
1085-
This requires :func:`Intents.members` to be enabled and will also add the members retrieved to :attr:`members`
1083+
This requires the :func:`~Intents.members` intent to be enabled and will also add the members retrieved to :attr:`members`
10861084
10871085
Examples
10881086
---------
1089-
1087+
10901088
Usage ::
1091-
1092-
print(f"The thread {channel.name} has the following members:\n")
1089+
1090+
print(f"The thread {channel.name} has the following members:\\n")
10931091
async for member in thread.fetch_members(limit=200):
10941092
print(member)
10951093
1096-
Flattening into a list: ::
1094+
1095+
Flattening into a list ::
10971096
10981097
messages = await thread.fetch_members(limit=123).flatten()
10991098
# messages is now a list of ThreadMember...
11001099
1100+
11011101
All parameters are optional.
11021102
11031103
Parameters
1104-
-----------
1104+
----------
11051105
limit: :class:`int`
11061106
The limit of thread members to retrieve - defaults to 100
11071107
after: Union[:class:`int`, :class:`datetime.datetime`]
11081108
Get thread members after this user ID
11091109
1110+
Raises
1111+
------
1112+
~discord.ClientException
1113+
The :attr:`~Intents.members` intent is not enabled.
1114+
11101115
Yields
11111116
-------
11121117
:class:`~discord.ThreadMember`
1113-
The thread member
1118+
A member of this thread
11141119
"""
11151120
if not self._state.intents.members:
11161121
raise ClientException('You need to enable the GUILD_MEMBERS Intent to use this API-call.')
@@ -2831,21 +2836,19 @@ async def create_post(
28312836
content: Any = None,
28322837
embed: Optional[Embed] = None,
28332838
embeds: Sequence[Embed] = None,
2834-
components: Optional[List[Union[ActionRow, List[Union[Button, SelectMenu]]]]] = None,
2839+
components: Optional[List[Union[ActionRow, List[Union[Button, BaseSelect]]]]] = None,
28352840
file: Optional[File] = None,
28362841
files: Sequence[File] = None,
28372842
allowed_mentions: Optional[AllowedMentions] = None,
2838-
suppress: bool = False,
2843+
suppress_embeds: bool = False,
2844+
supress_notifications: bool = False,
28392845
auto_archive_duration: Optional[AutoArchiveDuration] = None,
28402846
slowmode_delay: int = 0,
28412847
reason: Optional[str] = None
28422848
) -> ForumPost:
28432849
"""|coro|
28442850
2845-
Creates a new post in this forum.
2846-
2847-
You must have the :attr:`~Permissions.create_posts` permission to
2848-
use this.
2851+
Creates a new post in this forum. Requires the :attr:`~Permissions.create_posts` permission.
28492852
28502853
Parameters
28512854
-----------
@@ -2860,16 +2863,20 @@ async def create_post(
28602863
A embed of the post starter-message.
28612864
embeds: List[:class:`Embed`]
28622865
A list of up to 10 embeds to include in the post starter-message.
2863-
components: List[Union[:class:`ActionRow`, List[Union[:class:`Button`, :class:`SelectMenu`]]]]
2866+
components: List[Union[:class:`ActionRow`, List[Union[:class:`Button`, :class:`BaseSelect`]]]]
28642867
A list of components to include in the post starter-message.
28652868
file: Optional[class:`File`]
28662869
A file to include in the post starter-message.
28672870
files: List[:class:`File`]
28682871
A list of files to include in the post starter-message.
28692872
allowed_mentions: Optional[:class:`AllowedMentions`]
28702873
The allowed mentions for the post.
2871-
suppress: Optional[:class:`bool`]
2874+
suppress_embeds: Optional[:class:`bool`]
28722875
Whether to suppress embeds in the post starter-message.
2876+
supress_notifications: Optional[:class:`bool`]
2877+
Whether to suppress desktop- & push-notifications for the post starter-message.
2878+
2879+
Users will still see a ping-symbol when they are mentioned in the message, or the message is in a dm channel.
28732880
auto_archive_duration: Optional[:class:`AutoArchiveDuration`]
28742881
The duration after the post will be archived automatically when inactive.
28752882
slowmode_delay: Optional[:class:`int`]
@@ -2895,10 +2902,10 @@ async def create_post(
28952902
if self.flags.require_tags and not tags:
28962903
raise InvalidArgument('This forum requires at least one tag provided when creating a post.')
28972904

2898-
if suppress:
2899-
from .message import MessageFlags
2905+
if suppress_embeds or supress_notifications:
29002906
flags = MessageFlags._from_value(0)
2901-
flags.suppress_embeds = True
2907+
flags.suppress_embeds = suppress_embeds
2908+
flags.suppress_notifications = supress_notifications
29022909
else:
29032910
flags = MISSING
29042911

@@ -3060,4 +3067,4 @@ def _channel_factory(channel_type):
30603067
def _check_channel_type(obj, types) -> bool:
30613068
"""Just something to check channel instances without circular imports."""
30623069
types = tuple([_channel_factory(t)[0] for t in types])
3063-
return isinstance(obj, types)
3070+
return isinstance(obj, types)

0 commit comments

Comments
 (0)