@@ -119,8 +119,10 @@ class Interaction:
119
119
The interaction type.
120
120
guild_id: Optional[:class:`int`]
121
121
The guild ID the interaction was sent from.
122
- channel: Optional[Union[:class:`abc.GuildChannel`, :class:`abc.PrivateChannel`, :class:`Thread`]]
122
+ channel: Optional[Union[:class:`abc.GuildChannel`, :class:`abc.PrivateChannel`, :class:`Thread`, :class:`PartialMessageable` ]]
123
123
The channel the interaction was sent from.
124
+
125
+ Note that due to a Discord limitation, DM channels are not resolved since there is no data to complete them. These are :class:`PartialMessageable` instead.
124
126
channel_id: Optional[:class:`int`]
125
127
The ID of the channel the interaction was sent from.
126
128
application_id: :class:`int`
@@ -261,20 +263,32 @@ def _from_data(self, data: InteractionPayload):
261
263
except KeyError :
262
264
pass
263
265
264
- if channel := data .get ("channel" ):
265
- if (ch_type := channel .get ("type" )) is not None :
266
- factory , ch_type = _threaded_channel_factory (ch_type )
266
+ channel = data .get ("channel" )
267
+ data_ch_type : int | None = None
268
+ if channel :
269
+ data_ch_type = channel .get ("type" )
270
+
271
+ if data_ch_type is not None :
272
+ factory , ch_type = _threaded_channel_factory (data_ch_type )
273
+ if ch_type in (ChannelType .group , ChannelType .private ):
274
+ self .channel = factory (me = self .user , data = channel , state = self ._state )
275
+ elif self .guild :
276
+ self .channel = self .guild ._resolve_channel (self .channel_id ) or factory (
277
+ guild = self .guild , state = self ._state , data = channel
278
+ )
267
279
268
- if ch_type in (ChannelType .group , ChannelType .private ):
269
- self .channel = factory (
270
- me = self .user , data = channel , state = self ._state
271
- )
272
- elif self .guild :
273
- self .channel = factory (
274
- guild = self .guild , state = self ._state , data = channel
275
- )
276
- else :
277
- self .channel = self .cached_channel
280
+ if self .channel is None and self .guild :
281
+ self .channel = self .guild ._resolve_channel (self .channel_id )
282
+ if self .channel is None :
283
+ if self .channel_id is not None :
284
+ ch_type = (
285
+ ChannelType .text
286
+ if self .guild_id is not None
287
+ else ChannelType .private
288
+ )
289
+ return PartialMessageable (
290
+ state = self ._state , id = self .channel_id , type = ch_type
291
+ )
278
292
279
293
self ._channel_data = channel
280
294
@@ -305,29 +319,6 @@ def is_component(self) -> bool:
305
319
"""Indicates whether the interaction is a message component."""
306
320
return self .type == InteractionType .component
307
321
308
- @utils .cached_slot_property ("_cs_channel" )
309
- def cached_channel (self ) -> InteractionChannel | None :
310
- """The channel the
311
- interaction was sent from.
312
-
313
- Note that due to a Discord limitation, DM channels are not resolved since there is
314
- no data to complete them. These are :class:`PartialMessageable` instead.
315
- """
316
- guild = self .guild
317
- channel = guild and guild ._resolve_channel (self .channel_id )
318
- if channel is None :
319
- if self .channel_id is not None :
320
- type = (
321
- ChannelType .text
322
- if self .guild_id is not None
323
- else ChannelType .private
324
- )
325
- return PartialMessageable (
326
- state = self ._state , id = self .channel_id , type = type
327
- )
328
- return None
329
- return channel
330
-
331
322
@property
332
323
def permissions (self ) -> Permissions :
333
324
"""The resolved permissions of the member in the channel, including overwrites.
0 commit comments