Skip to content

Commit 9d9f70e

Browse files
committed
Add support for role flags
discord/discord-api-docs#6269
1 parent 270fa5f commit 9d9f70e

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

discord/flags.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,3 +1824,65 @@ def bypasses_verification(self):
18241824
def started_onboarding(self):
18251825
""":class:`bool`: Returns ``True`` if the member has started onboarding."""
18261826
return 1 << 3
1827+
1828+
1829+
class RoleFlags(BaseFlags):
1830+
r"""Wraps up the Discord Role flags
1831+
1832+
.. versionadded:: 2.2
1833+
1834+
.. container:: operations
1835+
1836+
.. describe:: x == y
1837+
1838+
Checks if two RoleFlags are equal.
1839+
1840+
.. describe:: x != y
1841+
1842+
Checks if two RoleFlags are not equal.
1843+
1844+
.. describe:: x | y, x |= y
1845+
1846+
Returns a RoleFlags instance with all enabled flags from
1847+
both x and y.
1848+
1849+
.. describe:: x & y, x &= y
1850+
1851+
Returns a RoleFlags instance with only flags enabled on
1852+
both x and y.
1853+
1854+
.. describe:: x ^ y, x ^= y
1855+
1856+
Returns a RoleFlags instance with only flags enabled on
1857+
only one of x or y, not on both.
1858+
1859+
.. describe:: ~x
1860+
1861+
Returns a RoleFlags instance with all flags inverted from x.
1862+
1863+
.. describe:: hash(x)
1864+
1865+
Return the flag's hash.
1866+
1867+
.. describe:: iter(x)
1868+
1869+
Returns an iterator of ``(name, value)`` pairs. This allows it
1870+
to be, for example, constructed as a dict or a list of pairs.
1871+
Note that aliases are not shown.
1872+
1873+
.. describe:: bool(b)
1874+
1875+
Returns whether any flag is set to ``True``.
1876+
1877+
1878+
Attributes
1879+
-----------
1880+
value: :class:`int`
1881+
The raw value. You should query flags via the properties
1882+
rather than using this raw value.
1883+
"""
1884+
1885+
@flag_value
1886+
def in_prompt(self):
1887+
""":class:`bool`: Returns ``True`` if the role can be selected by members in an onboarding prompt."""
1888+
return 1 << 0

discord/role.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .colour import Colour
3131
from .mixins import Hashable
3232
from .utils import snowflake_time, _bytes_to_base64_data, _get_as_snowflake, MISSING
33+
from .flags import RoleFlags
3334

3435
__all__ = (
3536
'RoleTags',
@@ -219,6 +220,7 @@ class Role(Hashable):
219220
'hoist',
220221
'guild',
221222
'tags',
223+
'_flags',
222224
'_state',
223225
)
224226

@@ -281,6 +283,7 @@ def _update(self, data: RolePayload):
281283
self.managed: bool = data.get('managed', False)
282284
self.mentionable: bool = data.get('mentionable', False)
283285
self.tags: Optional[RoleTags]
286+
self._flags: int = data.get('flags', 0)
284287

285288
try:
286289
self.tags = RoleTags(data['tags'])
@@ -379,6 +382,14 @@ def members(self) -> List[Member]:
379382
role_id = self.id
380383
return [member for member in all_members if member._roles.has(role_id)]
381384

385+
@property
386+
def flags(self) -> RoleFlags:
387+
""":class:`RoleFlags`: Returns the role's flags.
388+
389+
.. versionadded:: 2.4
390+
"""
391+
return RoleFlags._from_value(self._flags)
392+
382393
async def _move(self, position: int, reason: Optional[str]) -> None:
383394
if position <= 0:
384395
raise ValueError("Cannot move role to position 0 or below")

0 commit comments

Comments
 (0)