Skip to content

Commit 6e2a371

Browse files
committed
✨ Add new role tags and methods
1 parent 64313a8 commit 6e2a371

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

discord/role.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,32 @@ class RoleTags:
6868
The bot's user ID that manages this role.
6969
integration_id: Optional[:class:`int`]
7070
The integration ID that manages the role.
71+
subscription_listing_id: Optional[:class:`int`]
72+
The subscription listing ID for the role.
73+
.. versionadded:: 2.7
7174
"""
7275

7376
__slots__ = (
7477
"bot_id",
7578
"integration_id",
79+
"subscription_listing_id",
7680
"_premium_subscriber",
81+
"_available_for_purchase",
82+
"_guild_connections"
7783
)
7884

7985
def __init__(self, data: RoleTagPayload):
8086
self.bot_id: int | None = _get_as_snowflake(data, "bot_id")
8187
self.integration_id: int | None = _get_as_snowflake(data, "integration_id")
82-
# NOTE: The API returns "null" for this if it's valid, which corresponds to None.
88+
self.subscription_listing_id: int | None = _get_as_snowflake(data, "subscription_listing_id")
89+
# NOTE: The API returns "null" for this if the following tags True, and doesn't return them at all if False.
90+
# However, "null" corresponds to None.
8391
# This is different from other fields where "null" means "not there".
8492
# So in this case, a value of None is the same as True.
8593
# Which means we would need a different sentinel.
8694
self._premium_subscriber: Any | None = data.get("premium_subscriber", MISSING)
95+
self._available_for_purchase: Any | None = data.get("available_for_purchase", MISSING)
96+
self._guild_connections: Any | None = data.get("guild_connections", MISSING)
8797

8898
def is_bot_managed(self) -> bool:
8999
"""Whether the role is associated with a bot."""
@@ -97,10 +107,27 @@ def is_integration(self) -> bool:
97107
"""Whether the role is managed by an integration."""
98108
return self.integration_id is not None
99109

110+
def is_available_for_purchase(self) -> bool:
111+
"""Whether the role is available for purchase.
112+
113+
.. versionadded:: 2.7
114+
"""
115+
return self._available_for_purchase is None
116+
117+
def is_guild_connections_role(self) -> bool:
118+
"""Whether the role is a guild connections role.
119+
120+
.. versionadded:: 2.7
121+
"""
122+
return self._guild_connections is None
123+
100124
def __repr__(self) -> str:
101125
return (
102126
f"<RoleTags bot_id={self.bot_id} integration_id={self.integration_id} "
103-
f"premium_subscriber={self.is_premium_subscriber()}>"
127+
f"subscription_listing_id={self.subscription_listing_id} "
128+
f"premium_subscriber={self.is_premium_subscriber()} "
129+
f"available_for_purchase={self.is_available_for_purchase()} "
130+
f"guild_connections={self.is_guild_connections_role()}>"
104131
)
105132

106133

@@ -167,7 +194,9 @@ class Role(Hashable):
167194
operators on the role objects themselves.
168195
169196
managed: :class:`bool`
170-
Indicates if the role is managed by the guild. This is true if :meth:`Role.is_integration`, :meth:`Role.is_premium_subscriber`, or :meth:`Role.is_bot_managed` is ``True``.
197+
Indicates if the role is managed by the guild.
198+
This is true if any of :meth:`Role.is_integration`, :meth:`Role.is_premium_subscriber`,
199+
or :meth:`Role.is_bot_managed` are ``True``.
171200
mentionable: :class:`bool`
172201
Indicates if the role can be mentioned by users.
173202
tags: Optional[:class:`RoleTags`]
@@ -305,6 +334,20 @@ def is_assignable(self) -> bool:
305334
and (me.top_role > self or me.id == self.guild.owner_id)
306335
)
307336

337+
def is_available_for_purchase(self) -> bool:
338+
"""Whether the role is available for purchase.
339+
340+
.. versionadded:: 2.7
341+
"""
342+
return self.tags is not None and self.tags.is_available_for_purchase()
343+
344+
def is_guild_connections_role(self) -> bool:
345+
"""Whether the role is a guild connections role.
346+
347+
.. versionadded:: 2.7
348+
"""
349+
return self.tags is not None and self.tags.is_guild_connections_role()
350+
308351
@property
309352
def permissions(self) -> Permissions:
310353
"""Returns the role's permissions."""

0 commit comments

Comments
 (0)