Skip to content

Commit de117fe

Browse files
authored
feat: implement MemberFlags (#2489)
1 parent 267a644 commit de117fe

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ These changes are available on the `master` branch, but have not yet been releas
3434
([#2438](https://github.com/Pycord-Development/pycord/pull/2438))
3535
- Added `Attachment.title`.
3636
([#2486](https://github.com/Pycord-Development/pycord/pull/2486))
37+
- Added `MemberFlags`. ([#2489](https://github.com/Pycord-Development/pycord/pull/2489))
38+
- Added `bypass_verification` parameter to `Member.edit`.
39+
([#2489](https://github.com/Pycord-Development/pycord/pull/2489))
3740

3841
### Fixed
3942

discord/flags.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"ApplicationFlags",
4040
"ChannelFlags",
4141
"SKUFlags",
42+
"MemberFlags",
4243
)
4344

4445
FV = TypeVar("FV", bound="flag_value")
@@ -1684,3 +1685,76 @@ def guild_subscription(self):
16841685
def user_subscription(self):
16851686
""":class:`bool`: Returns ``True`` if the SKU is a user subscription."""
16861687
return 1 << 8
1688+
1689+
1690+
@fill_with_flags()
1691+
class MemberFlags(BaseFlags):
1692+
r"""Wraps up the Discord Member flags.
1693+
1694+
.. container:: operations
1695+
1696+
.. describe:: x == y
1697+
1698+
Checks if two MemberFlags are equal.
1699+
.. describe:: x != y
1700+
1701+
Checks if two MemberFlags are not equal.
1702+
.. describe:: x + y
1703+
1704+
Adds two flags together. Equivalent to ``x | y``.
1705+
.. describe:: x - y
1706+
1707+
Subtracts two flags from each other.
1708+
.. describe:: x | y
1709+
1710+
Returns the union of two flags. Equivalent to ``x + y``.
1711+
.. describe:: x & y
1712+
1713+
Returns the intersection of two flags.
1714+
.. describe:: ~x
1715+
1716+
Returns the inverse of a flag.
1717+
.. describe:: hash(x)
1718+
1719+
Return the flag's hash.
1720+
.. describe:: iter(x)
1721+
1722+
Returns an iterator of ``(name, value)`` pairs. This allows it
1723+
to be, for example, constructed as a dict or a list of pairs.
1724+
Note that aliases are not shown.
1725+
1726+
.. versionadded:: 2.6
1727+
1728+
Attributes
1729+
-----------
1730+
value: :class:`int`
1731+
The raw value. You should query flags via the properties
1732+
rather than using this raw value.
1733+
"""
1734+
1735+
__slots__ = ()
1736+
1737+
@flag_value
1738+
def did_rejoin(self):
1739+
""":class:`bool`: Returns ``True`` if the member left and rejoined the guild."""
1740+
return 1 << 0
1741+
1742+
@flag_value
1743+
def completed_onboarding(self):
1744+
""":class:`bool`: Returns ``True`` if the member has completed onboarding."""
1745+
return 1 << 1
1746+
1747+
@flag_value
1748+
def bypasses_verification(self):
1749+
""":class:`bool`: Returns ``True`` if the member is exempt from verification requirements.
1750+
1751+
.. note::
1752+
1753+
This can be edited through :func:`~discord.Member.edit`.
1754+
"""
1755+
return 1 << 2
1756+
1757+
@flag_value
1758+
def started_onboarding(self):
1759+
""":class:`bool`: Returns ``True`` if the member has started onboarding."""
1760+
return 1 << 3

discord/member.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from .asset import Asset
4040
from .colour import Colour
4141
from .enums import Status, try_enum
42+
from .flags import MemberFlags
4243
from .object import Object
4344
from .permissions import Permissions
4445
from .user import BaseUser, User, _UserTag
@@ -269,6 +270,10 @@ class Member(discord.abc.Messageable, _UserTag):
269270
An aware datetime object that specifies the date and time in UTC when the member will be removed from timeout.
270271
271272
.. versionadded:: 2.0
273+
flags: :class:`MemberFlags`
274+
Extra attributes of the member.
275+
276+
.. versionadded:: 2.6
272277
"""
273278

274279
__slots__ = (
@@ -284,6 +289,7 @@ class Member(discord.abc.Messageable, _UserTag):
284289
"_state",
285290
"_avatar",
286291
"communication_disabled_until",
292+
"flags",
287293
)
288294

289295
if TYPE_CHECKING:
@@ -325,6 +331,7 @@ def __init__(
325331
self.communication_disabled_until: datetime.datetime | None = utils.parse_time(
326332
data.get("communication_disabled_until")
327333
)
334+
self.flags: MemberFlags = MemberFlags._from_value(data.get("flags", 0))
328335

329336
def __str__(self) -> str:
330337
return str(self._user)
@@ -400,6 +407,7 @@ def _copy(cls: type[M], member: M) -> M:
400407
self._state = member._state
401408
self._avatar = member._avatar
402409
self.communication_disabled_until = member.communication_disabled_until
410+
self.flags = member.flags
403411

404412
# Reference will not be copied unless necessary by PRESENCE_UPDATE
405413
# See below
@@ -429,6 +437,7 @@ def _update(self, data: MemberPayload) -> None:
429437
self.communication_disabled_until = utils.parse_time(
430438
data.get("communication_disabled_until")
431439
)
440+
self.flags = MemberFlags._from_value(data.get("flags", 0))
432441

433442
def _presence_update(
434443
self, data: PartialPresenceUpdate, user: UserPayload
@@ -729,6 +738,7 @@ async def edit(
729738
voice_channel: VocalGuildChannel | None = MISSING,
730739
reason: str | None = None,
731740
communication_disabled_until: datetime.datetime | None = MISSING,
741+
bypass_verification: bool | None = MISSING,
732742
) -> Member | None:
733743
"""|coro|
734744
@@ -751,6 +761,18 @@ async def edit(
751761
+------------------------------+--------------------------------------+
752762
| communication_disabled_until | :attr:`Permissions.moderate_members` |
753763
+------------------------------+--------------------------------------+
764+
| bypass_verification | See note below |
765+
+------------------------------+--------------------------------------+
766+
767+
.. note::
768+
769+
`bypass_verification` may be edited under three scenarios:
770+
771+
- Client has :attr:`Permissions.manage_guild`
772+
773+
- Client has :attr:`Permissions.manage_roles`
774+
775+
- Client has ALL THREE of :attr:`Permissions.moderate_members`, :attr:`Permissions.kick_members`, and :attr:`Permissions.ban_members`
754776
755777
All parameters are optional.
756778
@@ -785,6 +807,10 @@ async def edit(
785807
from timeout.
786808
787809
.. versionadded:: 2.0
810+
bypass_verification: Optional[:class:`bool`]
811+
Indicates if the member should bypass the guild's verification requirements.
812+
813+
.. versionadded:: 2.6
788814
789815
Returns
790816
-------
@@ -849,6 +875,11 @@ async def edit(
849875
else:
850876
payload["communication_disabled_until"] = communication_disabled_until
851877

878+
if bypass_verification is not MISSING:
879+
flags = MemberFlags._from_value(self.flags.value)
880+
flags.bypasses_verification = bypass_verification
881+
payload["flags"] = flags.value
882+
852883
if payload:
853884
data = await http.edit_member(guild_id, self.id, reason=reason, **payload)
854885
return Member(data=data, guild=self.guild, state=self._state)

discord/types/member.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Member(PartialMember, total=False):
4848
pending: bool
4949
permissions: str
5050
communication_disabled_until: str
51+
flags: int
5152

5253

5354
class _OptionalMemberWithUser(PartialMember, total=False):

docs/api/data_classes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ Flags
166166
.. autoclass:: SKUFlags()
167167
:members:
168168

169+
.. attributetable:: MemberFlags
170+
171+
.. autoclass:: MemberFlags()
172+
:members:
173+
169174
Colour
170175
------
171176

0 commit comments

Comments
 (0)