Skip to content

Commit d231d63

Browse files
feat(commands): add Context.app_permissions and permissions as a shortcut to permissions_for self and author (#1429)
Signed-off-by: Zenith <[email protected]> Co-authored-by: vi <[email protected]>
1 parent 4b3ed4d commit d231d63

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

changelog/1429.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
|commands| Add :attr:`.Context.app_permissions` and :attr:`.Context.permissions` as a shorthands similar to :attr:`.Interaction.app_permissions` and :attr:`.Interaction.permissions`.

disnake/ext/commands/context.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import disnake.utils
1111
from disnake import ApplicationCommandInteraction
1212
from disnake.message import Message
13+
from disnake.permissions import Permissions
1314

1415
if TYPE_CHECKING:
1516
from typing_extensions import ParamSpec
@@ -284,6 +285,25 @@ def me(self) -> Union[Member, ClientUser]:
284285
# bot.user will never be None at this point.
285286
return self.guild.me if self.guild is not None else self.bot.user
286287

288+
@disnake.utils.cached_property
289+
def app_permissions(self) -> Permissions:
290+
""":class:`.Permissions`: Returns the permissions the bot has in the context's channel.
291+
292+
.. versionadded: |vnext|
293+
"""
294+
# This probably won't ever error.
295+
# `permissions_for` exists on all except PartialMessageable, which we shouldn't get here
296+
# For other channel types, permissions_for exists on all of them.
297+
return self.channel.permissions_for(self.me) # pyright: ignore[reportArgumentType]
298+
299+
@disnake.utils.cached_property
300+
def permissions(self) -> Permissions:
301+
""":class:`.Permissions`: Returns the permissions the author has in the context's channel.
302+
303+
.. versionadded: |vnext|
304+
"""
305+
return self.channel.permissions_for(self.author) # pyright: ignore[reportArgumentType]
306+
287307
@property
288308
def voice_client(self) -> Optional[VoiceProtocol]:
289309
r""":class:`.VoiceProtocol` | :data:`None`: A shortcut to :attr:`.Guild.voice_client`\, if applicable."""

0 commit comments

Comments
 (0)