Skip to content

Commit 28c2297

Browse files
authored
Merge branch 'master' into components/file-upload
2 parents 453008d + 830858c commit 28c2297

File tree

15 files changed

+156
-53
lines changed

15 files changed

+156
-53
lines changed

discord/abc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ async def _purge_helper(
195195
count = 0
196196
await asyncio.sleep(1)
197197

198+
if not message.type.is_deletable():
199+
continue
200+
198201
if not check(message):
199202
continue
200203

discord/channel.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,7 @@ async def create_thread(
28792879
applied_tags: Sequence[ForumTag] = ...,
28802880
view: LayoutView,
28812881
suppress_embeds: bool = ...,
2882+
silent: bool = ...,
28822883
reason: Optional[str] = ...,
28832884
) -> ThreadWithMessage: ...
28842885

@@ -2901,6 +2902,7 @@ async def create_thread(
29012902
applied_tags: Sequence[ForumTag] = ...,
29022903
view: View = ...,
29032904
suppress_embeds: bool = ...,
2905+
silent: bool = ...,
29042906
reason: Optional[str] = ...,
29052907
) -> ThreadWithMessage: ...
29062908

@@ -2922,6 +2924,7 @@ async def create_thread(
29222924
applied_tags: Sequence[ForumTag] = MISSING,
29232925
view: BaseView = MISSING,
29242926
suppress_embeds: bool = False,
2927+
silent: bool = False,
29252928
reason: Optional[str] = None,
29262929
) -> ThreadWithMessage:
29272930
"""|coro|
@@ -2976,6 +2979,11 @@ async def create_thread(
29762979
A list of stickers to upload. Must be a maximum of 3.
29772980
suppress_embeds: :class:`bool`
29782981
Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``.
2982+
silent: :class:`bool`
2983+
Whether to suppress push and desktop notifications for the message. This will increment the mention counter
2984+
in the UI, but will not actually send a notification.
2985+
2986+
.. versionadded:: 2.7
29792987
reason: :class:`str`
29802988
The reason for creating a new thread. Shows up on the audit log.
29812989
@@ -3008,8 +3016,10 @@ async def create_thread(
30083016
if view and not hasattr(view, '__discord_ui_view__'):
30093017
raise TypeError(f'view parameter must be View not {view.__class__.__name__}')
30103018

3011-
if suppress_embeds:
3012-
flags = MessageFlags._from_value(4)
3019+
if suppress_embeds or silent:
3020+
flags = MessageFlags._from_value(0)
3021+
flags.suppress_embeds = suppress_embeds
3022+
flags.suppress_notifications = silent
30133023
else:
30143024
flags = MISSING
30153025

discord/client.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,25 @@
124124
from .flags import MemberCacheFlags
125125

126126
class _ClientOptions(TypedDict, total=False):
127-
max_messages: int
128-
proxy: str
129-
proxy_auth: aiohttp.BasicAuth
130-
shard_id: int
131-
shard_count: int
127+
max_messages: Optional[int]
128+
proxy: Optional[str]
129+
proxy_auth: Optional[aiohttp.BasicAuth]
130+
shard_id: Optional[int]
131+
shard_count: Optional[int]
132132
application_id: int
133133
member_cache_flags: MemberCacheFlags
134134
chunk_guilds_at_startup: bool
135-
status: Status
136-
activity: BaseActivity
137-
allowed_mentions: AllowedMentions
135+
status: Optional[Status]
136+
activity: Optional[BaseActivity]
137+
allowed_mentions: Optional[AllowedMentions]
138138
heartbeat_timeout: float
139139
guild_ready_timeout: float
140140
assume_unsync_clock: bool
141141
enable_debug_events: bool
142142
enable_raw_presences: bool
143143
http_trace: aiohttp.TraceConfig
144-
max_ratelimit_timeout: float
145-
connector: aiohttp.BaseConnector
144+
max_ratelimit_timeout: Optional[float]
145+
connector: Optional[aiohttp.BaseConnector]
146146

147147

148148
# fmt: off
@@ -2511,7 +2511,7 @@ async def fetch_invite(
25112511
)
25122512
return Invite.from_incomplete(state=self._connection, data=data)
25132513

2514-
async def delete_invite(self, invite: Union[Invite, str], /) -> Invite:
2514+
async def delete_invite(self, invite: Union[Invite, str], /, *, reason: Optional[str]) -> Invite:
25152515
"""|coro|
25162516
25172517
Revokes an :class:`.Invite`, URL, or ID to an invite.
@@ -2527,6 +2527,8 @@ async def delete_invite(self, invite: Union[Invite, str], /) -> Invite:
25272527
----------
25282528
invite: Union[:class:`.Invite`, :class:`str`]
25292529
The invite to revoke.
2530+
reason: Optional[:class:`str`]
2531+
The reason for deleting the invite. Shows up on the audit log.
25302532
25312533
Raises
25322534
-------
@@ -2539,7 +2541,7 @@ async def delete_invite(self, invite: Union[Invite, str], /) -> Invite:
25392541
"""
25402542

25412543
resolved = utils.resolve_invite(invite)
2542-
data = await self.http.delete_invite(resolved.code)
2544+
data = await self.http.delete_invite(resolved.code, reason=reason)
25432545
return Invite.from_incomplete(state=self._connection, data=data)
25442546

25452547
# Miscellaneous stuff

discord/enums.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
'EntitlementType',
7676
'EntitlementOwnerType',
7777
'PollLayoutType',
78+
'InviteType',
79+
'ReactionType',
7880
'VoiceChannelEffectAnimationType',
7981
'SubscriptionStatus',
8082
'MessageReferenceType',
@@ -277,6 +279,16 @@ class MessageType(Enum):
277279
poll_result = 46
278280
emoji_added = 63
279281

282+
def is_deletable(self) -> bool:
283+
return self not in {
284+
MessageType.recipient_add,
285+
MessageType.recipient_remove,
286+
MessageType.call,
287+
MessageType.channel_name_change,
288+
MessageType.channel_icon_change,
289+
MessageType.thread_starter_message,
290+
}
291+
280292

281293
class SpeakingState(Enum):
282294
none = 0

discord/ext/commands/bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
PrefixType = Union[_Prefix, _PrefixCallable[BotT]]
9090

9191
class _BotOptions(_ClientOptions, total=False):
92-
owner_id: int
93-
owner_ids: Collection[int]
92+
owner_id: Optional[int]
93+
owner_ids: Optional[Collection[int]]
9494
strip_after_prefix: bool
9595
case_insensitive: bool
9696

discord/ext/commands/cog.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,18 @@
4545
Tuple,
4646
TypeVar,
4747
Union,
48-
TypedDict,
4948
)
5049

5150
from ._types import _BaseCommand, BotT
5251

5352
if TYPE_CHECKING:
54-
from typing_extensions import Self, Unpack
53+
from typing_extensions import Self
5554
from discord.abc import Snowflake
5655
from discord._types import ClientT
5756

5857
from .bot import BotBase
5958
from .context import Context
60-
from .core import Command, _CommandDecoratorKwargs
61-
62-
class _CogKwargs(TypedDict, total=False):
63-
name: str
64-
group_name: Union[str, app_commands.locale_str]
65-
description: str
66-
group_description: Union[str, app_commands.locale_str]
67-
group_nsfw: bool
68-
group_auto_locale_strings: bool
69-
group_extras: Dict[Any, Any]
70-
command_attrs: _CommandDecoratorKwargs
59+
from .core import Command
7160

7261

7362
__all__ = (
@@ -182,7 +171,7 @@ async def bar(self, ctx):
182171
__cog_app_commands__: List[Union[app_commands.Group, app_commands.Command[Any, ..., Any]]]
183172
__cog_listeners__: List[Tuple[str, str]]
184173

185-
def __new__(cls, *args: Any, **kwargs: Unpack[_CogKwargs]) -> CogMeta:
174+
def __new__(cls, *args: Any, **kwargs: Any) -> CogMeta:
186175
name, bases, attrs = args
187176
if any(issubclass(base, app_commands.Group) for base in bases):
188177
raise TypeError(

discord/ext/commands/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@
6868

6969
class _CommandDecoratorKwargs(TypedDict, total=False):
7070
enabled: bool
71-
help: str
72-
brief: str
73-
usage: str
71+
help: Optional[str]
72+
brief: Optional[str]
73+
usage: Optional[str]
7474
rest_is_raw: bool
75-
aliases: List[str]
75+
aliases: Union[List[str], Tuple[str, ...]]
7676
description: str
7777
hidden: bool
7878
checks: List[UserCheck[Context[Any]]]
@@ -449,7 +449,7 @@ def __init__(
449449
self.brief: Optional[str] = kwargs.get('brief')
450450
self.usage: Optional[str] = kwargs.get('usage')
451451
self.rest_is_raw: bool = kwargs.get('rest_is_raw', False)
452-
self.aliases: Union[List[str], Tuple[str]] = kwargs.get('aliases', [])
452+
self.aliases: Union[List[str], Tuple[str, ...]] = kwargs.get('aliases', [])
453453
self.extras: Dict[Any, Any] = kwargs.get('extras', {})
454454

455455
if not isinstance(self.aliases, (list, tuple)):

discord/ext/commands/help.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@
6969

7070
class _HelpCommandOptions(TypedDict, total=False):
7171
show_hidden: bool
72-
verify_checks: bool
72+
verify_checks: Optional[bool]
7373
command_attrs: _CommandKwargs
7474

7575
class _BaseHelpCommandOptions(_HelpCommandOptions, total=False):
7676
sort_commands: bool
77-
dm_help: bool
77+
dm_help: Optional[bool]
7878
dm_help_threshold: int
7979
no_category: str
8080
paginator: Paginator
@@ -394,7 +394,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Self:
394394

395395
def __init__(self, **options: Unpack[_HelpCommandOptions]) -> None:
396396
self.show_hidden: bool = options.pop('show_hidden', False)
397-
self.verify_checks: bool = options.pop('verify_checks', True)
397+
self.verify_checks: Optional[bool] = options.pop('verify_checks', True)
398398
self.command_attrs = attrs = options.pop('command_attrs', {})
399399
attrs.setdefault('name', 'help')
400400
attrs.setdefault('help', 'Shows this message')
@@ -1070,7 +1070,7 @@ def __init__(self, **options: Unpack[_DefaultHelpCommandOptions]) -> None:
10701070
self.width: int = options.pop('width', 80)
10711071
self.indent: int = options.pop('indent', 2)
10721072
self.sort_commands: bool = options.pop('sort_commands', True)
1073-
self.dm_help: bool = options.pop('dm_help', False)
1073+
self.dm_help: Optional[bool] = options.pop('dm_help', False)
10741074
self.dm_help_threshold: int = options.pop('dm_help_threshold', 1000)
10751075
self.arguments_heading: str = options.pop('arguments_heading', 'Arguments:')
10761076
self.commands_heading: str = options.pop('commands_heading', 'Commands:')
@@ -1364,7 +1364,7 @@ class MinimalHelpCommand(HelpCommand):
13641364
def __init__(self, **options: Unpack[_MinimalHelpCommandOptions]) -> None:
13651365
self.sort_commands: bool = options.pop('sort_commands', True)
13661366
self.commands_heading: str = options.pop('commands_heading', 'Commands')
1367-
self.dm_help: bool = options.pop('dm_help', False)
1367+
self.dm_help: Optional[bool] = options.pop('dm_help', False)
13681368
self.dm_help_threshold: int = options.pop('dm_help_threshold', 1000)
13691369
self.aliases_heading: str = options.pop('aliases_heading', 'Aliases:')
13701370
self.no_category: str = options.pop('no_category', 'No Category')

discord/ext/commands/hybrid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ class _HybridGroupKwargs(_HybridCommandDecoratorKwargs, total=False):
6767
default_permissions: bool
6868
nsfw: bool
6969
description: str
70+
case_insensitive: bool
7071

7172
class _HybridGroupDecoratorKwargs(_HybridGroupKwargs, total=False):
7273
description: Union[str, app_commands.locale_str]
73-
fallback: Union[str, app_commands.locale_str]
74+
fallback: Optional[str]
75+
fallback_locale: Optional[app_commands.locale_str]
7476

7577

7678
__all__ = (

discord/http.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,18 +1136,15 @@ def guild_voice_state(
11361136
def edit_profile(self, payload: Dict[str, Any]) -> Response[user.User]:
11371137
return self.request(Route('PATCH', '/users/@me'), json=payload)
11381138

1139-
def change_my_nickname(
1139+
def edit_my_member(
11401140
self,
11411141
guild_id: Snowflake,
1142-
nickname: str,
11431142
*,
11441143
reason: Optional[str] = None,
1145-
) -> Response[member.Nickname]:
1146-
r = Route('PATCH', '/guilds/{guild_id}/members/@me/nick', guild_id=guild_id)
1147-
payload = {
1148-
'nick': nickname,
1149-
}
1150-
return self.request(r, json=payload, reason=reason)
1144+
**fields: Any,
1145+
) -> Response[member.MemberWithUser]:
1146+
r = Route('PATCH', '/guilds/{guild_id}/members/@me', guild_id=guild_id)
1147+
return self.request(r, json=fields, reason=reason)
11511148

11521149
def change_nickname(
11531150
self,

0 commit comments

Comments
 (0)