29
29
from typing import TYPE_CHECKING , Any , Coroutine , Union
30
30
31
31
from . import utils
32
- from .channel import ChannelType , PartialMessageable
32
+ from .channel import ChannelType , PartialMessageable , _threaded_channel_factory
33
33
from .enums import InteractionResponseType , InteractionType , try_enum
34
34
from .errors import ClientException , InteractionResponded , InvalidArgument
35
35
from .file import File
57
57
58
58
from .channel import (
59
59
CategoryChannel ,
60
+ DMChannel ,
60
61
ForumChannel ,
62
+ GroupChannel ,
61
63
StageChannel ,
62
64
TextChannel ,
63
65
VoiceChannel ,
82
84
ForumChannel ,
83
85
CategoryChannel ,
84
86
Thread ,
87
+ DMChannel ,
88
+ GroupChannel ,
85
89
PartialMessageable ,
86
90
]
87
91
@@ -104,8 +108,10 @@ class Interaction:
104
108
The interaction type.
105
109
guild_id: Optional[:class:`int`]
106
110
The guild ID the interaction was sent from.
111
+ channel: Optional[Union[:class:`abc.GuildChannel`, :class:`abc.PrivateChannel`, :class:`Thread`]]
112
+ The channel the interaction was sent from.
107
113
channel_id: Optional[:class:`int`]
108
- The channel ID the interaction was sent from.
114
+ The ID of the channel the interaction was sent from.
109
115
application_id: :class:`int`
110
116
The application ID that the interaction was for.
111
117
user: Optional[Union[:class:`User`, :class:`Member`]]
@@ -129,6 +135,7 @@ class Interaction:
129
135
"id" ,
130
136
"type" ,
131
137
"guild_id" ,
138
+ "channel" ,
132
139
"channel_id" ,
133
140
"data" ,
134
141
"application_id" ,
@@ -139,6 +146,7 @@ class Interaction:
139
146
"token" ,
140
147
"version" ,
141
148
"custom_id" ,
149
+ "_channel_data" ,
142
150
"_message_data" ,
143
151
"_permissions" ,
144
152
"_app_permissions" ,
@@ -174,13 +182,7 @@ def _from_data(self, data: InteractionPayload):
174
182
self ._app_permissions : int = int (data .get ("app_permissions" , 0 ))
175
183
176
184
self .message : Message | None = None
177
-
178
- if message_data := data .get ("message" ):
179
- self .message = Message (
180
- state = self ._state , channel = self .channel , data = message_data
181
- )
182
-
183
- self ._message_data = message_data
185
+ self .channel = None
184
186
185
187
self .user : User | Member | None = None
186
188
self ._permissions : int = 0
@@ -211,6 +213,30 @@ def _from_data(self, data: InteractionPayload):
211
213
except KeyError :
212
214
pass
213
215
216
+ if channel := data .get ("channel" ):
217
+ if (ch_type := channel .get ("type" )) is not None :
218
+ factory , ch_type = _threaded_channel_factory (ch_type )
219
+
220
+ if ch_type in (ChannelType .group , ChannelType .private ):
221
+ self .channel = factory (
222
+ me = self .user , data = channel , state = self ._state
223
+ )
224
+ elif self .guild :
225
+ self .channel = factory (
226
+ guild = self .guild , state = self ._state , data = channel
227
+ )
228
+ else :
229
+ self .channel = self .cached_channel
230
+
231
+ self ._channel_data = channel
232
+
233
+ if message_data := data .get ("message" ):
234
+ self .message = Message (
235
+ state = self ._state , channel = self .channel , data = message_data
236
+ )
237
+
238
+ self ._message_data = message_data
239
+
214
240
@property
215
241
def client (self ) -> Client :
216
242
"""Returns the client that sent the interaction."""
@@ -230,7 +256,7 @@ def is_component(self) -> bool:
230
256
return self .type == InteractionType .component
231
257
232
258
@utils .cached_slot_property ("_cs_channel" )
233
- def channel (self ) -> InteractionChannel | None :
259
+ def cached_channel (self ) -> InteractionChannel | None :
234
260
"""The channel the
235
261
interaction was sent from.
236
262
0 commit comments