37
37
38
38
from .commands import ApplicationCommand , Option
39
39
from ..cog import Cog
40
+ from ..webhook import WebhookMessage
41
+ from typing import Callable
40
42
41
43
from ..guild import Guild
42
44
from ..interactions import Interaction , InteractionResponse
54
56
else :
55
57
P = TypeVar ('P' )
56
58
57
- __all__ = (
58
- "ApplicationContext" ,
59
- "AutocompleteContext"
60
- )
59
+ __all__ = ("ApplicationContext" , "AutocompleteContext" )
60
+
61
61
62
62
class ApplicationContext (discord .abc .Messageable ):
63
63
"""Represents a Discord application command interaction context.
@@ -162,35 +162,39 @@ def author(self) -> Optional[Union[Member, User]]:
162
162
def voice_client (self ):
163
163
if self .guild is None :
164
164
return None
165
-
165
+
166
166
return self .guild .voice_client
167
167
168
168
@cached_property
169
169
def response (self ) -> InteractionResponse :
170
170
return self .interaction .response
171
171
172
172
@property
173
- def respond (self ):
174
- if not self .response .is_done ():
175
- return self .interaction .response .send_message
176
- else :
177
- raise RuntimeError (f"Interaction was already issued a response. Try using { type (self ).__name__ } .send_followup() instead." )
178
-
179
- @property
180
- async def send_response (self ) -> Callable [..., Union [Interaction , Webhook ]]:
173
+ def respond (self ) -> Callable [..., Union [Interaction , WebhookMessage ]]:
181
174
"""Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
182
175
or a followup response depending if the interaction has been responded to yet or not."""
183
176
if not self .response .is_done ():
184
177
return self .interaction .response .send_message # self.response
185
178
else :
186
179
return self .followup .send # self.send_followup
187
180
181
+ @property
182
+ def send_response (self ):
183
+ if not self .response .is_done ():
184
+ return self .interaction .response .send_message
185
+ else :
186
+ raise RuntimeError (
187
+ f"Interaction was already issued a response. Try using { type (self ).__name__ } .send_followup() instead."
188
+ )
189
+
188
190
@property
189
191
def send_followup (self ):
190
192
if self .response .is_done ():
191
193
return self .followup .send
192
194
else :
193
- raise RuntimeError (f"Interaction was not yet issued a response. Try using { type (self ).__name__ } .respond() first." )
195
+ raise RuntimeError (
196
+ f"Interaction was not yet issued a response. Try using { type (self ).__name__ } .respond() first."
197
+ )
194
198
195
199
@property
196
200
def defer (self ):
@@ -217,7 +221,7 @@ def cog(self) -> Optional[Cog]:
217
221
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
218
222
if self .command is None :
219
223
return None
220
-
224
+
221
225
return self .command .cog
222
226
223
227
@@ -231,7 +235,7 @@ class AutocompleteContext:
231
235
Attributes
232
236
-----------
233
237
bot: :class:`.Bot`
234
- The bot that the command belongs to.
238
+ The bot that the command belongs to.
235
239
interaction: :class:`.Interaction`
236
240
The interaction object that invoked the autocomplete.
237
241
command: :class:`.ApplicationCommand`
@@ -245,7 +249,7 @@ class AutocompleteContext:
245
249
"""
246
250
247
251
__slots__ = ("bot" , "interaction" , "command" , "focused" , "value" , "options" )
248
-
252
+
249
253
def __init__ (self , bot : Bot , interaction : Interaction ) -> None :
250
254
self .bot = bot
251
255
self .interaction = interaction
@@ -260,5 +264,5 @@ def cog(self) -> Optional[Cog]:
260
264
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
261
265
if self .command is None :
262
266
return None
263
-
267
+
264
268
return self .command .cog
0 commit comments