Repository: Rapptz/discord.py
File: discord/interactions.py (Python)

Code before:
        )
        self.response_message_loading: Optional[bool] = interaction.get('response_message_loading')
        self.response_message_ephemeral: Optional[bool] = interaction.get('response_message_ephemeral')

        resource = data.get('resource', {})
        self.callback_type: Optional[InteractionResponseType] = None
        self.activity_instance: Optional[InteractionCallbackActivity] = None
        self.response_message: Optional[InteractionMessage] = None

        try:
            self.callback_type = try_enum(InteractionResponseType, resource['type'])
        except KeyError:
            pass

        try:
            self.activity_instance = InteractionCallbackActivity(
                data=resource['activity_instance'],
            )
        except KeyError:
            pass

        try:
            self.response_message = InteractionMessage(
                state=self._state,
                channel=self.response_channel,  # type: ignore
                data=resource['message'],
            )
        except KeyError:
            pass


class InteractionResponse(Generic[ClientT]):
    """Represents a Discord interaction response.

    This type can be accessed through :attr:`Interaction.response`.

    .. versionadded:: 2.0
    """

    __slots__: Tuple[str, ...] = (
        '_response_type',
        '_parent',
    )

    def __init__(self, parent: Interaction[ClientT]):
        self._parent: Interaction[ClientT] = parent
        self._response_type: Optional[InteractionResponseType] = None

    def is_done(self) -> bool:
        """:class:`bool`: Indicates whether an interaction response has been done before.


Review comment (suggestion):
According to Discord API [documentation](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-callback-interaction-callback-resource-object), `message` here is only present for interaction callback types `4` and `7`, so class docstring above should mention that and have an entry for it in our docs as well 👍🏼 

Code after:
                    state=self._state,
                    channel=self._parent.channel,  # type: ignore # channel should be the correct type here
                    data=message,
                )
            elif activity_instance is not None:
                self.resource = InteractionCallbackActivityInstance(activity_instance)

    def is_thinking(self) -> bool:
        """:class:`bool`: Whether the response was a thinking defer."""
        return self._thinking

    def is_ephemeral(self) -> bool:
        """:class:`bool`: Whether the response was ephemeral."""
        return self._ephemeral


class InteractionResponse(Generic[ClientT]):
    """Represents a Discord interaction response.

    This type can be accessed through :attr:`Interaction.response`.

    .. versionadded:: 2.0
    """

    __slots__: Tuple[str, ...] = (
        '_response_type',
        '_parent',
    )

    def __init__(self, parent: Interaction[ClientT]):
        self._parent: Interaction[ClientT] = parent
        self._response_type: Optional[InteractionResponseType] = None

    def is_done(self) -> bool:
        """:class:`bool`: Indicates whether an interaction response has been done before.

        An interaction can only be responded to once.
        """
        return self._response_type is not None

    @property
    def type(self) -> Optional[InteractionResponseType]:
        """:class:`InteractionResponseType`: The type of response that was sent, ``None`` if response is not done."""
        return self._response_type

    async def defer(
        self,
        *,
        ephemeral: bool = False,
        thinking: bool = False,
    ) -> Optional[InteractionCallback[ClientT]]: