Skip to content

Commit 5706da0

Browse files
authored
Merge branch 'Pycord-Development:master' into master
2 parents b0c815f + a4b44ca commit 5706da0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2011
-210
lines changed

.github/workflows/test.yml

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ jobs:
1717
matrix:
1818
os: [ubuntu-latest, macos-latest, windows-latest]
1919
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
20+
# Python 3.8/3.9 are on macos-13 but not macos-latest (macos-14-arm64)
21+
# https://github.com/actions/setup-python/issues/696#issuecomment-1637587760
22+
exclude:
23+
- { python-version: "3.8", os: "macos-latest" }
24+
- { python-version: "3.9", os: "macos-latest" }
25+
include:
26+
- { python-version: "3.8", os: "macos-13" }
27+
- { python-version: "3.9", os: "macos-13" }
28+
2029
env:
2130
OS: ${{ matrix.os }}
2231
PYTHON: ${{ matrix.python-version }}

.github/workflows/todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
steps:
77
- uses: actions/checkout@v4
88
- name: Run tdg-github-action
9-
uses: ribtoks/tdg-github-action@v0.4.10-beta
9+
uses: ribtoks/tdg-github-action@v0.4.11-beta
1010
with:
1111
TOKEN: ${{ secrets.GITHUB_TOKEN }}
1212
REPO: ${{ github.repository }}

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
# - --remove-duplicate-keys
2020
# - --remove-unused-variables
2121
- repo: https://github.com/asottile/pyupgrade
22-
rev: v3.15.2
22+
rev: v3.16.0
2323
hooks:
2424
- id: pyupgrade
2525
args: [--py38-plus]
@@ -28,7 +28,7 @@ repos:
2828
hooks:
2929
- id: isort
3030
- repo: https://github.com/psf/black
31-
rev: 24.4.0
31+
rev: 24.4.2
3232
hooks:
3333
- id: black
3434
args: [--safe, --quiet]

CHANGELOG.md

+29
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ These changes are available on the `master` branch, but have not yet been releas
2020
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
2121
- Added `Guild.search_members`.
2222
([#2418](https://github.com/Pycord-Development/pycord/pull/2418))
23+
- Added bulk banning up to 200 users through `Guild.bulk_ban`.
24+
([#2421](https://github.com/Pycord-Development/pycord/pull/2421))
2325
- Added `member` data to the `raw_reaction_remove` event.
2426
([#2412](https://github.com/Pycord-Development/pycord/pull/2412))
27+
- Added `Poll` and all related features.
28+
([#2408](https://github.com/Pycord-Development/pycord/pull/2408))
29+
- Added `stacklevel` param to `utils.warn_deprecated` and `utils.deprecated`.
30+
([#2450](https://github.com/Pycord-Development/pycord/pull/2450))
31+
- Added support for user-installable applications.
32+
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)
2533

2634
### Fixed
2735

@@ -42,6 +50,16 @@ These changes are available on the `master` branch, but have not yet been releas
4250
([#2411](https://github.com/Pycord-Development/pycord/pull/2411))
4351
- Fixed option typehints being ignored when using `parameter_name`.
4452
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
53+
- Fixed parameter `embed=None` causing `AttributeError` on `PartialMessage.edit`.
54+
([#2446](https://github.com/Pycord-Development/pycord/pull/2446))
55+
- Fixed paginator to revert state if a page update callback fails.
56+
([#2448](https://github.com/Pycord-Development/pycord/pull/2448))
57+
- Fixed missing `application_id` in `Entitlement.delete`.
58+
([#2458](https://github.com/Pycord-Development/pycord/pull/2458))
59+
- Fixed many inaccurate type hints throughout the library.
60+
([#2457](https://github.com/Pycord-Development/pycord/pull/2457))
61+
- Fixed `AttributeError` due to `discord.Option` being initialised with `input_type` set
62+
to `None`. ([#2464](https://github.com/Pycord-Development/pycord/pull/2464))
4563

4664
### Changed
4765

@@ -55,6 +73,17 @@ These changes are available on the `master` branch, but have not yet been releas
5573
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
5674
- `Guild.query_members` now accepts `limit=None` to retrieve all members.
5775
([#2419](https://github.com/Pycord-Development/pycord/pull/2419))
76+
- `ApplicationCommand.guild_only` is now deprecated in favor of
77+
`ApplicationCommand.contexts`.
78+
([#2409](https://github.com/Pycord-Development/pycord/pull/2409))
79+
- `Message.interaction` is now deprecated in favor of `Message.interaction_metadata`.
80+
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)
81+
82+
### Removed
83+
84+
- Removed the `delete_message_days` parameter from ban methods. Please use
85+
`delete_message_seconds` instead.
86+
([#2421](https://github.com/Pycord-Development/pycord/pull/2421))
5887

5988
## [2.5.0] - 2024-03-02
6089

discord/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
from .partial_emoji import *
5959
from .permissions import *
6060
from .player import *
61+
from .poll import *
6162
from .raw_models import *
6263
from .reaction import *
6364
from .role import *

discord/abc.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
from .guild import Guild
9090
from .member import Member
9191
from .message import Message, MessageReference, PartialMessage
92+
from .poll import Poll
9293
from .state import ConnectionState
9394
from .threads import Thread
9495
from .types.channel import Channel as ChannelPayload
@@ -115,7 +116,7 @@ async def _single_delete_strategy(
115116

116117

117118
async def _purge_messages_helper(
118-
channel: TextChannel | Thread | VoiceChannel,
119+
channel: TextChannel | StageChannel | Thread | VoiceChannel,
119120
*,
120121
limit: int | None = 100,
121122
check: Callable[[Message], bool] = MISSING,
@@ -1345,12 +1346,13 @@ async def send(
13451346
file: File = ...,
13461347
stickers: Sequence[GuildSticker | StickerItem] = ...,
13471348
delete_after: float = ...,
1348-
nonce: str | int = ...,
1349+
nonce: int | str = ...,
13491350
enforce_nonce: bool = ...,
13501351
allowed_mentions: AllowedMentions = ...,
13511352
reference: Message | MessageReference | PartialMessage = ...,
13521353
mention_author: bool = ...,
13531354
view: View = ...,
1355+
poll: Poll = ...,
13541356
suppress: bool = ...,
13551357
silent: bool = ...,
13561358
) -> Message: ...
@@ -1365,12 +1367,13 @@ async def send(
13651367
files: list[File] = ...,
13661368
stickers: Sequence[GuildSticker | StickerItem] = ...,
13671369
delete_after: float = ...,
1368-
nonce: str | int = ...,
1370+
nonce: int | str = ...,
13691371
enforce_nonce: bool = ...,
13701372
allowed_mentions: AllowedMentions = ...,
13711373
reference: Message | MessageReference | PartialMessage = ...,
13721374
mention_author: bool = ...,
13731375
view: View = ...,
1376+
poll: Poll = ...,
13741377
suppress: bool = ...,
13751378
silent: bool = ...,
13761379
) -> Message: ...
@@ -1385,12 +1388,13 @@ async def send(
13851388
file: File = ...,
13861389
stickers: Sequence[GuildSticker | StickerItem] = ...,
13871390
delete_after: float = ...,
1388-
nonce: str | int = ...,
1391+
nonce: int | str = ...,
13891392
enforce_nonce: bool = ...,
13901393
allowed_mentions: AllowedMentions = ...,
13911394
reference: Message | MessageReference | PartialMessage = ...,
13921395
mention_author: bool = ...,
13931396
view: View = ...,
1397+
poll: Poll = ...,
13941398
suppress: bool = ...,
13951399
silent: bool = ...,
13961400
) -> Message: ...
@@ -1405,12 +1409,13 @@ async def send(
14051409
files: list[File] = ...,
14061410
stickers: Sequence[GuildSticker | StickerItem] = ...,
14071411
delete_after: float = ...,
1408-
nonce: str | int = ...,
1412+
nonce: int | str = ...,
14091413
enforce_nonce: bool = ...,
14101414
allowed_mentions: AllowedMentions = ...,
14111415
reference: Message | MessageReference | PartialMessage = ...,
14121416
mention_author: bool = ...,
14131417
view: View = ...,
1418+
poll: Poll = ...,
14141419
suppress: bool = ...,
14151420
silent: bool = ...,
14161421
) -> Message: ...
@@ -1432,6 +1437,7 @@ async def send(
14321437
reference=None,
14331438
mention_author=None,
14341439
view=None,
1440+
poll=None,
14351441
suppress=None,
14361442
silent=None,
14371443
):
@@ -1465,7 +1471,7 @@ async def send(
14651471
The file to upload.
14661472
files: List[:class:`~discord.File`]
14671473
A list of files to upload. Must be a maximum of 10.
1468-
nonce: :class:`int`
1474+
nonce: Union[:class:`str`, :class:`int`]
14691475
The nonce to use for sending this message. If the message was successfully sent,
14701476
then the message will have a nonce with this value.
14711477
enforce_nonce: Optional[:class:`bool`]
@@ -1515,6 +1521,10 @@ async def send(
15151521
Whether to suppress push and desktop notifications for the message.
15161522
15171523
.. versionadded:: 2.4
1524+
poll: :class:`Poll`
1525+
The poll to send.
1526+
1527+
.. versionadded:: 2.6
15181528
15191529
Returns
15201530
-------
@@ -1594,6 +1604,9 @@ async def send(
15941604
else:
15951605
components = None
15961606

1607+
if poll:
1608+
poll = poll.to_dict()
1609+
15971610
if file is not None and files is not None:
15981611
raise InvalidArgument("cannot pass both file and files parameter to send()")
15991612

@@ -1616,6 +1629,7 @@ async def send(
16161629
stickers=stickers,
16171630
components=components,
16181631
flags=flags,
1632+
poll=poll,
16191633
)
16201634
finally:
16211635
file.close()
@@ -1643,6 +1657,7 @@ async def send(
16431657
stickers=stickers,
16441658
components=components,
16451659
flags=flags,
1660+
poll=poll,
16461661
)
16471662
finally:
16481663
for f in files:
@@ -1661,6 +1676,7 @@ async def send(
16611676
stickers=stickers,
16621677
components=components,
16631678
flags=flags,
1679+
poll=poll,
16641680
)
16651681

16661682
ret = state.create_message(channel=channel, data=data)

discord/audit_logs.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ def _transform_type(
193193

194194
def _transform_actions(
195195
entry: AuditLogEntry, data: list[AutoModActionPayload] | None
196-
) -> AutoModAction | None:
196+
) -> list[AutoModAction] | None:
197197
if data is None:
198198
return None
199199
else:
200200
return [AutoModAction.from_dict(d) for d in data]
201201

202202

203203
def _transform_trigger_metadata(
204-
entry: AuditLogEntry, data: list[AutoModActionPayload] | None
205-
) -> AutoModAction | None:
204+
entry: AuditLogEntry, data: AutoModTriggerMetadataPayload | None
205+
) -> AutoModTriggerMetadata | None:
206206
if data is None:
207207
return None
208208
else:
@@ -309,7 +309,7 @@ def __init__(
309309
"$add_allow_list",
310310
]:
311311
self._handle_trigger_metadata(
312-
self.before, self.after, entry, elem["new_value"], attr
312+
self.before, self.after, entry, elem["new_value"], attr # type: ignore
313313
)
314314
continue
315315
elif attr in [
@@ -318,7 +318,7 @@ def __init__(
318318
"$remove_allow_list",
319319
]:
320320
self._handle_trigger_metadata(
321-
self.after, self.before, entry, elem["new_value"], attr
321+
self.after, self.before, entry, elem["new_value"], attr # type: ignore
322322
)
323323
continue
324324

discord/bot.py

+50-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
UserCommand,
4949
command,
5050
)
51-
from .enums import InteractionType
51+
from .enums import IntegrationType, InteractionContextType, InteractionType
5252
from .errors import CheckFailure, DiscordException
5353
from .interactions import Interaction
5454
from .shard import AutoShardedClient
@@ -125,6 +125,13 @@ def add_application_command(self, command: ApplicationCommand) -> None:
125125

126126
if self._bot.debug_guilds and command.guild_ids is None:
127127
command.guild_ids = self._bot.debug_guilds
128+
if self._bot.default_command_contexts and command.contexts is None:
129+
command.contexts = self._bot.default_command_contexts
130+
if (
131+
self._bot.default_command_integration_types
132+
and command.integration_types is None
133+
):
134+
command.integration_types = self._bot.default_command_integration_types
128135

129136
for cmd in self.pending_application_commands:
130137
if cmd == command:
@@ -271,7 +278,6 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
271278
else:
272279
as_dict = cmd.to_dict()
273280
to_check = {
274-
"dm_permission": None,
275281
"nsfw": None,
276282
"default_member_permissions": None,
277283
"name": None,
@@ -287,6 +293,8 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
287293
"name_localizations",
288294
"description_localizations",
289295
],
296+
"contexts": None,
297+
"integration_types": None,
290298
}
291299
for check, value in to_check.items():
292300
if type(to_check[check]) == list:
@@ -1157,6 +1165,21 @@ def __init__(self, description=None, *args, **options):
11571165
self.auto_sync_commands = options.get("auto_sync_commands", True)
11581166

11591167
self.debug_guilds = options.pop("debug_guilds", None)
1168+
self.default_command_contexts = options.pop(
1169+
"default_command_contexts",
1170+
{
1171+
InteractionContextType.guild,
1172+
InteractionContextType.bot_dm,
1173+
InteractionContextType.private_channel,
1174+
},
1175+
)
1176+
1177+
self.default_command_integration_types = options.pop(
1178+
"default_command_integration_types",
1179+
{
1180+
IntegrationType.guild_install,
1181+
},
1182+
)
11601183

11611184
if self.owner_id and self.owner_ids:
11621185
raise TypeError("Both owner_id and owner_ids are set.")
@@ -1167,6 +1190,20 @@ def __init__(self, description=None, *args, **options):
11671190
raise TypeError(
11681191
f"owner_ids must be a collection not {self.owner_ids.__class__!r}"
11691192
)
1193+
if not isinstance(self.default_command_contexts, collections.abc.Collection):
1194+
raise TypeError(
1195+
f"default_command_contexts must be a collection not {self.default_command_contexts.__class__!r}"
1196+
)
1197+
if not isinstance(
1198+
self.default_command_integration_types, collections.abc.Collection
1199+
):
1200+
raise TypeError(
1201+
f"default_command_integration_types must be a collection not {self.default_command_integration_types.__class__!r}"
1202+
)
1203+
self.default_command_contexts = set(self.default_command_contexts)
1204+
self.default_command_integration_types = set(
1205+
self.default_command_integration_types
1206+
)
11701207

11711208
self._checks = []
11721209
self._check_once = []
@@ -1447,6 +1484,17 @@ class Bot(BotBase, Client):
14471484
:attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
14481485
14491486
.. versionadded:: 2.0
1487+
default_command_contexts: Collection[:class:`InteractionContextType`]
1488+
The default context types that the bot will use for commands.
1489+
Defaults to a set containing :attr:`InteractionContextType.guild`, :attr:`InteractionContextType.bot_dm`, and
1490+
:attr:`InteractionContextType.private_channel`.
1491+
1492+
.. versionadded:: 2.6
1493+
default_command_integration_types: Collection[:class:`IntegrationType`]]
1494+
The default integration types that the bot will use for commands.
1495+
Defaults to a set containing :attr:`IntegrationType.guild_install`.
1496+
1497+
.. versionadded:: 2.6
14501498
"""
14511499

14521500
@property

discord/channel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ async def create_thread(
12181218
A list of stickers to upload. Must be a maximum of 3.
12191219
delete_message_after: :class:`int`
12201220
The time to wait before deleting the thread.
1221-
nonce: :class:`int`
1221+
nonce: Union[:class:`str`, :class:`int`]
12221222
The nonce to use for sending this message. If the message was successfully sent,
12231223
then the message will have a nonce with this value.
12241224
allowed_mentions: :class:`~discord.AllowedMentions`

0 commit comments

Comments
 (0)