diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf7cd67cb..6ec3411622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ These changes are available on the `master` branch, but have not yet been releas - Added `stacklevel` param to `utils.warn_deprecated` and `utils.deprecated`. ([#2450](https://github.com/Pycord-Development/pycord/pull/2450)) - Added support for user-installable applications. - ([#2409](https://github.com/Pycord-Development/pycord/pull/2409) + ([#2409](https://github.com/Pycord-Development/pycord/pull/2409)) - Added support for one-time purchases for Discord monetization. ([#2438](https://github.com/Pycord-Development/pycord/pull/2438)) - Added `Attachment.title`. @@ -93,7 +93,10 @@ These changes are available on the `master` branch, but have not yet been releas `ApplicationCommand.contexts`. ([#2409](https://github.com/Pycord-Development/pycord/pull/2409)) - `Message.interaction` is now deprecated in favor of `Message.interaction_metadata`. - ([#2409](https://github.com/Pycord-Development/pycord/pull/2409) + ([#2409](https://github.com/Pycord-Development/pycord/pull/2409)) +- Replaced `Client.fetch_entitlements` with `Client.entitlements`, which returns an + `EntitlementIterator`. + ([#2490](https://github.com/Pycord-Development/pycord/pull/2490)) ### Removed diff --git a/discord/client.py b/discord/client.py index 0044272d59..4cfaef59cf 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2043,7 +2043,7 @@ async def fetch_skus(self) -> list[SKU]: data = await self._connection.http.list_skus(self.application_id) return [SKU(data=s) for s in data] - async def fetch_entitlements( + def entitlements( self, user: Snowflake | None = None, skus: list[Snowflake] | None = None, @@ -2053,11 +2053,9 @@ async def fetch_entitlements( guild: Snowflake | None = None, exclude_ended: bool = False, ) -> EntitlementIterator: - """|coro| - - Fetches the bot's entitlements. + """Returns an :class:`.AsyncIterator` that enables fetching the application's entitlements. - .. versionadded:: 2.5 + .. versionadded:: 2.6 Parameters ---------- @@ -2083,24 +2081,38 @@ async def fetch_entitlements( Whether to limit the fetched entitlements to those that have not ended. Defaults to ``False``. - Returns - ------- - List[:class:`.Entitlement`] + Yields + ------ + :class:`.Entitlement` The application's entitlements. Raises ------ :exc:`HTTPException` Retrieving the entitlements failed. + + Examples + -------- + + Usage :: + + async for entitlement in client.entitlements(): + print(entitlement.user_id) + + Flattening into a list :: + + entitlements = await user.entitlements().flatten() + + All parameters are optional. """ return EntitlementIterator( self._connection, - user_id=user.id, - sku_ids=[sku.id for sku in skus], + user_id=user.id if user else None, + sku_ids=[sku.id for sku in skus] if skus else None, before=before, after=after, limit=limit, - guild_id=guild.id, + guild_id=guild.id if guild else None, exclude_ended=exclude_ended, ) diff --git a/discord/guild.py b/discord/guild.py index 515d7e43af..f1bbe14aa2 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -68,7 +68,12 @@ from .flags import SystemChannelFlags from .integrations import Integration, _integration_factory from .invite import Invite -from .iterators import AuditLogIterator, BanIterator, MemberIterator +from .iterators import ( + AuditLogIterator, + BanIterator, + EntitlementIterator, + MemberIterator, +) from .member import Member, VoiceState from .mixins import Hashable from .monetization import Entitlement @@ -4071,7 +4076,7 @@ async def create_test_entitlement(self, sku: Snowflake) -> Entitlement: data = await self._state.http.create_test_entitlement(self.id, payload) return Entitlement(data=data, state=self._state) - async def fetch_entitlements( + def entitlements( self, skus: list[Snowflake] | None = None, before: SnowflakeTime | None = None, @@ -4079,11 +4084,9 @@ async def fetch_entitlements( limit: int | None = 100, exclude_ended: bool = False, ) -> EntitlementIterator: - """|coro| + """Returns an :class:`.AsyncIterator` that enables fetching the guild's entitlements. - Fetches this guild's entitlements. - - This is identical to :meth:`Client.fetch_entitlements` with the ``guild`` parameter. + This is identical to :meth:`Client.entitlements` with the ``guild`` parameter. .. versionadded:: 2.6 @@ -4107,9 +4110,9 @@ async def fetch_entitlements( Whether to limit the fetched entitlements to those that have not ended. Defaults to ``False``. - Returns - ------- - List[:class:`.Entitlement`] + Yields + ------ + :class:`.Entitlement` The application's entitlements. Raises @@ -4119,7 +4122,7 @@ async def fetch_entitlements( """ return EntitlementIterator( self._state, - sku_ids=[sku.id for sku in skus], + sku_ids=[sku.id for sku in skus] if skus else None, before=before, after=after, limit=limit, diff --git a/discord/http.py b/discord/http.py index e3d6e7dcc9..b29b35d4b2 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2980,7 +2980,7 @@ def list_entitlements( if guild_id is not None: params["guild_id"] = guild_id if exclude_ended is not None: - params["exclude_ended"] = exclude_ended + params["exclude_ended"] = int(exclude_ended) r = Route( "GET", diff --git a/discord/ui/button.py b/discord/ui/button.py index bdd49d21f8..5487fd6b73 100644 --- a/discord/ui/button.py +++ b/discord/ui/button.py @@ -117,7 +117,7 @@ def __init__( ) self._provided_custom_id = custom_id is not None - if url is None and custom_id is None: + if url is None and custom_id is None and sku_id is None: custom_id = os.urandom(16).hex() if url is not None: diff --git a/discord/user.py b/discord/user.py index 5c2f41feb1..d986a018f5 100644 --- a/discord/user.py +++ b/discord/user.py @@ -639,7 +639,7 @@ async def create_test_entitlement(self, sku: discord.abc.Snowflake) -> Entitleme data = await self._state.http.create_test_entitlement(self.id, payload) return Entitlement(data=data, state=self._state) - async def fetch_entitlements( + def entitlements( self, skus: list[Snowflake] | None = None, before: SnowflakeTime | None = None, @@ -647,11 +647,9 @@ async def fetch_entitlements( limit: int | None = 100, exclude_ended: bool = False, ) -> EntitlementIterator: - """|coro| - - Fetches this user's entitlements. + """Returns an :class:`.AsyncIterator` that enables fetching the user's entitlements. - This is identical to :meth:`Client.fetch_entitlements` with the ``user`` parameter. + This is identical to :meth:`Client.entitlements` with the ``user`` parameter. .. versionadded:: 2.6 @@ -675,9 +673,9 @@ async def fetch_entitlements( Whether to limit the fetched entitlements to those that have not ended. Defaults to ``False``. - Returns - ------- - List[:class:`.Entitlement`] + Yields + ------ + :class:`.Entitlement` The application's entitlements. Raises @@ -687,7 +685,7 @@ async def fetch_entitlements( """ return EntitlementIterator( self._state, - sku_ids=[sku.id for sku in skus], + sku_ids=[sku.id for sku in skus] if skus else None, before=before, after=after, limit=limit,