Skip to content

Commit bb1d09a

Browse files
Kileowocado
andauthored
Account for user installations in Channel.permissions_for
Co-authored-by: owocado <24418520+owocado@users.noreply.github.com>
1 parent 895d6c3 commit bb1d09a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

discord/abc.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ def permissions_for(self, obj: Union[Member, Role], /) -> Permissions:
699699
- Member overrides
700700
- Implicit permissions
701701
- Member timeout
702+
- User installed app
702703
703704
If a :class:`~discord.Role` is passed, then it checks the permissions
704705
someone with that role would have, which is essentially:
@@ -714,6 +715,12 @@ def permissions_for(self, obj: Union[Member, Role], /) -> Permissions:
714715
.. versionchanged:: 2.0
715716
``obj`` parameter is now positional-only.
716717
718+
.. versionchanged:: 2.4
719+
User installed apps are now taken into account.
720+
The permissions returned for a user installed app mirrors the
721+
permissions Discord returns in :attr:`~discord.Interaction.app_permissions`,
722+
though it is recommended to use that attribute instead.
723+
717724
Parameters
718725
----------
719726
obj: Union[:class:`~discord.Member`, :class:`~discord.Role`]
@@ -745,6 +752,13 @@ def permissions_for(self, obj: Union[Member, Role], /) -> Permissions:
745752
return Permissions.all()
746753

747754
default = self.guild.default_role
755+
if default is None:
756+
757+
if self._state.self_id == obj.id:
758+
return Permissions._user_installed_permissions(in_guild=True)
759+
else:
760+
return Permissions.none()
761+
748762
base = Permissions(default.permissions.value)
749763

750764
# Handle the role case first

discord/permissions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ def _dm_permissions(cls) -> Self:
208208
base.send_messages_in_threads = False
209209
return base
210210

211+
@classmethod
212+
def _user_installed_permissions(cls, *, in_guild: bool) -> Self:
213+
base = cls.none()
214+
base.send_messages = True
215+
base.attach_files = True
216+
base.embed_links = True
217+
base.external_emojis = True
218+
base.send_voice_messages = True
219+
if in_guild:
220+
# Logically this is False but if not set to True,
221+
# permissions just become 0.
222+
base.read_messages = True
223+
base.send_tts_messages = True
224+
base.send_messages_in_threads = True
225+
return base
226+
211227
@classmethod
212228
def all_channel(cls) -> Self:
213229
"""A :class:`Permissions` with all channel-specific permissions set to

0 commit comments

Comments
 (0)