Skip to content

Commit e593485

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

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

discord/role.py

Lines changed: 44 additions & 2 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

@@ -305,6 +332,21 @@ def is_assignable(self) -> bool:
305332
and (me.top_role > self or me.id == self.guild.owner_id)
306333
)
307334

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

0 commit comments

Comments
 (0)