35
35
36
36
from .commands import ApplicationCommand , Option
37
37
from ..cog import Cog
38
+ from ..webhook import Webhook
39
+ from typing import Callable
38
40
39
41
from ..guild import Guild
40
42
from ..interactions import Interaction , InteractionResponse
43
45
from ..user import User
44
46
from ..utils import cached_property
45
47
46
- __all__ = (
47
- "ApplicationContext" ,
48
- "AutocompleteContext"
49
- )
48
+ __all__ = ("ApplicationContext" , "AutocompleteContext" )
49
+
50
50
51
51
class ApplicationContext (discord .abc .Messageable ):
52
52
"""Represents a Discord application command interaction context.
@@ -125,35 +125,39 @@ def author(self) -> Optional[Union[Member, User]]:
125
125
def voice_client (self ):
126
126
if self .guild is None :
127
127
return None
128
-
128
+
129
129
return self .guild .voice_client
130
130
131
131
@cached_property
132
132
def response (self ) -> InteractionResponse :
133
133
return self .interaction .response
134
134
135
135
@property
136
- def respond (self ):
137
- if not self .response .is_done ():
138
- return self .interaction .response .send_message
139
- else :
140
- raise RuntimeError (f"Interaction was already issued a response. Try using { type (self ).__name__ } .send_followup() instead." )
141
-
142
- @property
143
- async def send_response (self ) -> Callable [..., Union [Interaction , Webhook ]]:
136
+ def respond (self ) -> Callable [..., Union [Interaction , Webhook ]]:
144
137
"""Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
145
138
or a followup response depending if the interaction has been responded to yet or not."""
146
139
if not self .response .is_done ():
147
140
return self .interaction .response .send_message # self.response
148
141
else :
149
142
return self .followup .send # self.send_followup
150
143
144
+ @property
145
+ def send_response (self ):
146
+ if not self .response .is_done ():
147
+ return self .interaction .response .send_message
148
+ else :
149
+ raise RuntimeError (
150
+ f"Interaction was already issued a response. Try using { type (self ).__name__ } .send_followup() instead."
151
+ )
152
+
151
153
@property
152
154
def send_followup (self ):
153
155
if self .response .is_done ():
154
156
return self .followup .send
155
157
else :
156
- raise RuntimeError (f"Interaction was not yet issued a response. Try using { type (self ).__name__ } .respond() first." )
158
+ raise RuntimeError (
159
+ f"Interaction was not yet issued a response. Try using { type (self ).__name__ } .respond() first."
160
+ )
157
161
158
162
@property
159
163
def defer (self ):
@@ -180,7 +184,7 @@ def cog(self) -> Optional[Cog]:
180
184
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
181
185
if self .command is None :
182
186
return None
183
-
187
+
184
188
return self .command .cog
185
189
186
190
@@ -194,7 +198,7 @@ class AutocompleteContext:
194
198
Attributes
195
199
-----------
196
200
bot: :class:`.Bot`
197
- The bot that the command belongs to.
201
+ The bot that the command belongs to.
198
202
interaction: :class:`.Interaction`
199
203
The interaction object that invoked the autocomplete.
200
204
command: :class:`.ApplicationCommand`
@@ -208,7 +212,7 @@ class AutocompleteContext:
208
212
"""
209
213
210
214
__slots__ = ("bot" , "interaction" , "command" , "focused" , "value" , "options" )
211
-
215
+
212
216
def __init__ (self , bot : Bot , interaction : Interaction ) -> None :
213
217
self .bot = bot
214
218
self .interaction = interaction
@@ -223,5 +227,5 @@ def cog(self) -> Optional[Cog]:
223
227
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
224
228
if self .command is None :
225
229
return None
226
-
230
+
227
231
return self .command .cog
0 commit comments