Skip to content

Commit

Permalink
fix(commands): fix permission check edge case (#2253)
Browse files Browse the repository at this point in the history
* fix(commands): permissions error with appcmd scope

Refer to #2113

* chore(commands): don't put partial guild in cache

* Apply suggestions from code review

Co-authored-by: Dorukyum <[email protected]>
Signed-off-by: Middledot <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Dorukyum <[email protected]>

---------

Signed-off-by: Middledot <[email protected]>
Signed-off-by: Dorukyum <[email protected]>
Co-authored-by: Dorukyum <[email protected]>
  • Loading branch information
Middledot and Dorukyum authored Nov 29, 2023
1 parent 257d61a commit 99725dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2240](https://github.com/Pycord-Development/pycord/pull/2240))
- Fixed tasks looping infinitely when `tzinfo` is neither `None` nor UTC.
([#2196](https://github.com/Pycord-Development/pycord/pull/2196))
- Fixed `AttributeError` when running permission checks without the `bot` scope.
([#2113](https://github.com/Pycord-Development/pycord/issues/2113))

## [2.4.1] - 2023-03-20

Expand Down
2 changes: 1 addition & 1 deletion discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def permissions_for(self, obj: Member | Role, /) -> Permissions:
return Permissions.all()

default = self.guild.default_role
base = Permissions(default.permissions.value)
base = Permissions(default.permissions.value if default else 0)

# Handle the role case first
if isinstance(obj, Role):
Expand Down
9 changes: 9 additions & 0 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class Interaction:
"custom_id",
"_channel_data",
"_message_data",
"_guild_data",
"_guild",
"_permissions",
"_app_permissions",
"_state",
Expand Down Expand Up @@ -188,6 +190,11 @@ def _from_data(self, data: InteractionPayload):
self.user: User | Member | None = None
self._permissions: int = 0

self._guild: Guild | None = None
self._guild_data = data.get("guild")
if self.guild is None and self._guild_data:
self._guild = Guild(data=self._guild_data, state=self)

# TODO: there's a potential data loss here
if self.guild_id:
guild = (
Expand Down Expand Up @@ -246,6 +253,8 @@ def client(self) -> Client:
@property
def guild(self) -> Guild | None:
"""The guild the interaction was sent from."""
if self._guild:
return self._guild
return self._state and self._state._get_guild(self.guild_id)

def is_command(self) -> bool:
Expand Down

0 comments on commit 99725dd

Please sign in to comment.