Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement app_permissions and fix stuff #1460

Merged
merged 18 commits into from
Jul 2, 2022
Merged
5 changes: 5 additions & 0 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from ..member import Member
from ..message import Message
from ..user import User
from ..permissions import Permissions
from ..client import ClientUser
from discord.webhook.async_ import Webhook

Expand Down Expand Up @@ -158,6 +159,10 @@ def locale(self) -> Optional[str]:
def guild_locale(self) -> Optional[str]:
return self.interaction.guild_locale

@cached_property
def app_permissions(self) -> Permissions:
return self.interaction.app_permissions

@cached_property
def me(self) -> Optional[Union[Member, ClientUser]]:
return self.interaction.guild.me if self.interaction.guild is not None else self.bot.user
Expand Down
1 change: 1 addition & 0 deletions discord/ext/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"MessageConverter",
"PartialMessageConverter",
"TextChannelConverter",
"ForumChannelConverter",
"InviteConverter",
"GuildConverter",
"RoleConverter",
Expand Down
15 changes: 13 additions & 2 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

from .channel import (
CategoryChannel,
PartialMessageable,
StageChannel,
TextChannel,
VoiceChannel,
Expand Down Expand Up @@ -137,6 +136,7 @@ class Interaction:
"custom_id",
"_message_data",
"_permissions",
"_app_permissions",
"_state",
"_session",
"_original_message",
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -163,6 +163,7 @@ def _from_data(self, data: InteractionPayload):
self.locale: Optional[str] = data.get("locale")
self.guild_locale: Optional[str] = data.get("guild_locale")
self.custom_id: Optional[str] = self.data.get("custom_id") if self.data is not None else None
self._app_permissions: int = int(data.get("app_permissions"))
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved

self.message: Optional[Message] = None

Expand Down Expand Up @@ -233,6 +234,11 @@ def permissions(self) -> Permissions:
"""
return Permissions(self._permissions)

@property
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
def app_permissions(self) -> Permissions:
""":class:`Permissions`: The resolved permissions of the application in the channel, including overwrites."""
return Permissions(self._app_permissions)

@utils.cached_slot_property("_cs_response")
def response(self) -> InteractionResponse:
""":class:`InteractionResponse`: Returns an object responsible for handling responding to the interaction.
Expand Down Expand Up @@ -493,13 +499,17 @@ def is_done(self) -> bool:

async def defer(self, *, ephemeral: bool = False, invisible: bool = True) -> None:
"""|coro|

Defers the interaction response.

This is typically used when the interaction is acknowledged
and a secondary action will be done later.
This is can only be used with the following interaction types

This is can only be used with the following interaction types:
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
- :attr:`InteractionType.application_command`
- :attr:`InteractionType.component`
- :attr:`InteractionType.modal_submit`

Parameters
-----------
ephemeral: :class:`bool`
Expand All @@ -511,6 +521,7 @@ async def defer(self, *, ephemeral: bool = False, invisible: bool = True) -> Non
In the Discord UI, this is represented as the bot thinking of a response. You must
eventually send a followup message via :attr:`Interaction.followup` to make this thinking state go away.
This parameter does not apply to interactions of type :attr:`InteractionType.application_command`.

Raises
-------
HTTPException
Expand Down
2 changes: 2 additions & 0 deletions discord/types/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .role import Role
from .snowflake import Snowflake
from .user import User
from ..permissions import Permissions

if TYPE_CHECKING:
from .message import AllowedMentions, Message
Expand Down Expand Up @@ -202,6 +203,7 @@ class _InteractionOptional(TypedDict, total=False):
message: Message
locale: str
guild_locale: str
app_permissions: Permissions
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved


class Interaction(_InteractionOptional):
Expand Down
4 changes: 2 additions & 2 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ instead. Similar to this example: ::
# good
await asyncio.sleep(10)

Another common source of blocking for too long is using HTTP requests with the famous module :doc:`req:index`.
While :doc:`req:index` is an amazing module for non-asynchronous programming, it is not a good choice for
Another common source of blocking for too long is using HTTP requests with the famous module :doc:`requests:index`.
While :doc:`requests:index` is an amazing module for non-asynchronous programming, it is not a good choice for
:mod:`asyncio` because certain requests can block the event loop too long. Instead, use the :doc:`aiohttp <aio:index>` library which
is installed on the side with this library.

Expand Down