Skip to content

Commit cb9837d

Browse files
Lulalabyplun1331UnBonWhiskypre-commit-ci[bot]
committed
fix: patch team permissions keyerror and use teamrole instead
fix: don't consider read_only as app owner Co-Authored-By: plun1331 <plun1331@gmail.com> Co-Authored-By: ffouqueray <flavien.fouqueray@icloud.com> Co-Authored-By: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 94f03db commit cb9837d

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

discord/bot.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,8 @@ async def is_owner(self, user: User | Member) -> bool:
14411441
this bot.
14421442
14431443
If an :attr:`owner_id` is not set, it is fetched automatically
1444-
through the use of :meth:`~.Bot.application_info`.
1444+
through the use of :meth:`~.Bot.application_info`, returning
1445+
the application owner, or all non read-only team members.
14451446
14461447
.. versionchanged:: 1.3
14471448
The function also checks if the application is team-owned if
@@ -1465,7 +1466,9 @@ async def is_owner(self, user: User | Member) -> bool:
14651466
else:
14661467
app = await self.application_info() # type: ignore
14671468
if app.team:
1468-
self.owner_ids = ids = {m.id for m in app.team.members}
1469+
self.owner_ids = ids = {
1470+
m.id for m in app.team.members if m.role != "read_only"
1471+
}
14691472
return user.id in ids
14701473
else:
14711474
self.owner_id = owner_id = app.owner.id
@@ -1491,11 +1494,12 @@ class Bot(BotBase, Client):
14911494
owner_id: Optional[:class:`int`]
14921495
The user ID that owns the bot. If this is not set and is then queried via
14931496
:meth:`.is_owner` then it is fetched automatically using
1494-
:meth:`~.Bot.application_info`.
1497+
:meth:`~.Bot.application_info`, returning the application owner.
14951498
owner_ids: Optional[Collection[:class:`int`]]
14961499
The user IDs that owns the bot. This is similar to :attr:`owner_id`.
14971500
If this is not set and the application is team based, then it is
1498-
fetched automatically using :meth:`~.Bot.application_info`.
1501+
fetched automatically using :meth:`~.Bot.application_info`,
1502+
returning all non read-only team members.
14991503
For performance reasons it is recommended to use a :class:`set`
15001504
for the collection. You cannot set both ``owner_id`` and ``owner_ids``.
15011505

discord/enums.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"ActivityType",
4646
"NotificationLevel",
4747
"TeamMembershipState",
48+
"TeamRole",
4849
"WebhookType",
4950
"ExpireBehaviour",
5051
"ExpireBehavior",
@@ -629,6 +630,15 @@ class TeamMembershipState(Enum):
629630
accepted = 2
630631

631632

633+
class TeamRole(Enum):
634+
"""Role of a team member."""
635+
636+
owner = "owner"
637+
admin = "admin"
638+
developer = "developer"
639+
read_only = "read_only"
640+
641+
632642
class WebhookType(Enum):
633643
"""Webhook Type"""
634644

discord/team.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from . import utils
3131
from .asset import Asset
32-
from .enums import TeamMembershipState, try_enum
32+
from .enums import TeamMembershipState, TeamRole, try_enum
3333
from .user import BaseUser
3434

3535
if TYPE_CHECKING:
@@ -136,16 +136,22 @@ class TeamMember(BaseUser):
136136
The team that the member is from.
137137
membership_state: :class:`TeamMembershipState`
138138
The membership state of the member (e.g. invited or accepted)
139+
role: :class:`TeamRole`
140+
The role of the team member (e.g. admin, developer, read_only).
139141
"""
140142

141-
__slots__ = ("team", "membership_state", "permissions")
143+
__slots__ = ("team", "membership_state", "role")
142144

143145
def __init__(self, team: Team, state: ConnectionState, data: TeamMemberPayload):
144146
self.team: Team = team
145147
self.membership_state: TeamMembershipState = try_enum(
146148
TeamMembershipState, data["membership_state"]
147149
)
148-
self.permissions: list[str] = data["permissions"]
150+
self.role: TeamRole = (
151+
TeamRole.owner
152+
if team.owner_id == int(data["user"]["id"])
153+
else try_enum(TeamRole, data["role"])
154+
)
149155
super().__init__(state=state, data=data["user"])
150156

151157
def __repr__(self) -> str:

discord/types/team.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
class TeamMember(TypedDict):
3535
user: PartialUser
3636
membership_state: int
37-
permissions: list[str]
37+
role: str
3838
team_id: Snowflake
3939

4040

0 commit comments

Comments
 (0)