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

Code before:
        '_cs_response',
        '_cs_followup',
        '_cs_namespace',
        '_cs_command',
        'channel',
    )

    def __init__(self, *, data: InteractionPayload, state: ConnectionState[ClientT]):
        self._state: ConnectionState[ClientT] = state
        self._client: ClientT = state._get_client()
        self._session: ClientSession = state.http._HTTPClient__session  # type: ignore # Mangled attribute for __session
        self._original_response: Optional[InteractionMessage] = None
        # This baton is used for extra data that might be useful for the lifecycle of
        # an interaction. This is mainly for internal purposes and it gives it a free-for-all slot.
        self._baton: Any = MISSING
        self.extras: Dict[Any, Any] = {}
        self.command_failed: bool = False
        self._from_data(data)

    def _from_data(self, data: InteractionPayload):
        self.id: int = int(data['id'])
        self.type: InteractionType = try_enum(InteractionType, data['type'])
        self.data: Optional[InteractionData] = data.get('data')
        self.token: str = data['token']
        self.version: int = data['version']
        self.channel_id: Optional[int] = utils._get_as_snowflake(data, 'channel_id')
        self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id')
        self.channel: Optional[InteractionChannel] = None

        channel_type = data.get('channel', {}).get('type')
        if channel_type is not None:
            factory, ch_type = _threaded_channel_factory(channel_type)
            if factory is None:
                raise InvalidData('Unknown channel type {type} for channel ID {id}.'.format_map(data))

            channel = data['channel']
            if ch_type in (ChannelType.group, ChannelType.private):
                channel = factory(me=self._client.user, data=channel, state=self._state)  # type: ignore
            else:
                guild = self._state._get_guild(self.guild_id)
                channel = factory(guild=guild, state=self._state, data=channel)  # type: ignore

            self.channel = channel

        self.application_id: int = int(data['application_id'])

        self.locale: Locale = try_enum(Locale, data.get('locale', 'en-US'))
        self.guild_locale: Optional[Locale]
        try:
            self.guild_locale = try_enum(Locale, data['guild_locale'])
        except KeyError:

Review comment (suggestion):
the docs mention we should stop using this, and instead use the id in the `channel` field. Maybe do that too.

Code after:
        '_cs_response',
        '_cs_followup',
        'channel',
        '_cs_namespace',
        '_cs_command',
    )

    def __init__(self, *, data: InteractionPayload, state: ConnectionState[ClientT]):
        self._state: ConnectionState[ClientT] = state
        self._client: ClientT = state._get_client()
        self._session: ClientSession = state.http._HTTPClient__session  # type: ignore # Mangled attribute for __session
        self._original_response: Optional[InteractionMessage] = None
        # This baton is used for extra data that might be useful for the lifecycle of
        # an interaction. This is mainly for internal purposes and it gives it a free-for-all slot.
        self._baton: Any = MISSING
        self.extras: Dict[Any, Any] = {}
        self.command_failed: bool = False
        self._from_data(data)

    def _from_data(self, data: InteractionPayload):
        self.id: int = int(data['id'])
        self.type: InteractionType = try_enum(InteractionType, data['type'])
        self.data: Optional[InteractionData] = data.get('data')
        self.token: str = data['token']
        self.version: int = data['version']
        self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id')
        self.channel: Optional[InteractionChannel] = None

        raw_channel = data.get('channel', {})
        raw_ch_type = raw_channel.get('type')
        if raw_ch_type is not None:
            factory, ch_type = _threaded_channel_factory(raw_ch_type)  # type is never None
            if factory is None:
                logging.info('Unknown channel type {type} for channel ID {id}.'.format_map(raw_channel))
            else:
                if ch_type in (ChannelType.group, ChannelType.private):
                    channel = factory(me=self._client.user, data=raw_channel, state=self._state)  # type: ignore
                else:
                    guild = self._state._get_or_create_unavailable_guild(self.guild_id)  # type: ignore
                    channel = factory(guild=guild, state=self._state, data=raw_channel)  # type: ignore

                self.channel = channel

        self.application_id: int = int(data['application_id'])

        self.locale: Locale = try_enum(Locale, data.get('locale', 'en-US'))
        self.guild_locale: Optional[Locale]
        try:
            self.guild_locale = try_enum(Locale, data['guild_locale'])
        except KeyError:
            self.guild_locale = None