2727from typing import TYPE_CHECKING , Optional , TypeVar , Union
2828
2929import discord .abc
30+ from discord .interactions import InteractionMessage
3031
3132if TYPE_CHECKING :
3233 from typing_extensions import ParamSpec
3334
3435 import discord
35- from discord import Bot
36- from discord .state import ConnectionState
36+ from .. import Bot
37+ from ..state import ConnectionState
38+ from ..voice_client import VoiceProtocol
3739
3840 from .core import ApplicationCommand , Option
41+ from ..interactions import Interaction , InteractionResponse , InteractionChannel
42+ from ..guild import Guild
43+ from ..member import Member
44+ from ..message import Message
45+ from ..user import User
46+ from ..client import ClientUser
47+ from discord .webhook .async_ import Webhook
48+
3949 from ..cog import Cog
4050 from ..webhook import WebhookMessage
41- from typing import Callable
51+
52+ from typing import Callable , Awaitable
4253
43- from ..guild import Guild
44- from ..interactions import Interaction , InteractionResponse
45- from ..member import Member
46- from ..message import Message
47- from ..user import User
48- from ..utils import cached_property
54+ from ..utils import _cached_property as cached_property
4955
5056T = TypeVar ('T' )
5157CogT = TypeVar ('CogT' , bound = "Cog" )
@@ -88,8 +94,8 @@ def __init__(self, bot: Bot, interaction: Interaction):
8894
8995 self ._state : ConnectionState = self .interaction ._state
9096
91- async def _get_channel (self ) -> discord . abc . Messageable :
92- return self .channel
97+ async def _get_channel (self ) -> Optional [ InteractionChannel ] :
98+ return self .interaction . channel
9399
94100 async def invoke (self , command : ApplicationCommand [CogT , P , T ], / , * args : P .args , ** kwargs : P .kwargs ) -> T :
95101 r"""|coro|
@@ -118,7 +124,7 @@ async def invoke(self, command: ApplicationCommand[CogT, P, T], /, *args: P.args
118124 return await command (self , * args , ** kwargs )
119125
120126 @cached_property
121- def channel (self ):
127+ def channel (self ) -> Optional [ InteractionChannel ] :
122128 return self .interaction .channel
123129
124130 @cached_property
@@ -142,8 +148,8 @@ def guild_locale(self) -> Optional[str]:
142148 return self .interaction .guild_locale
143149
144150 @cached_property
145- def me (self ) -> Union [Member , User ]:
146- return self .guild .me if self .guild is not None else self .bot .user
151+ def me (self ) -> Optional [ Union [Member , ClientUser ] ]:
152+ return self .interaction . guild .me if self . interaction .guild is not None else self .bot .user
147153
148154 @cached_property
149155 def message (self ) -> Optional [Message ]:
@@ -153,66 +159,64 @@ def message(self) -> Optional[Message]:
153159 def user (self ) -> Optional [Union [Member , User ]]:
154160 return self .interaction .user
155161
156- @cached_property
157- def author (self ) -> Optional [Union [Member , User ]]:
158- return self .user
162+ author = user
159163
160164 @property
161- def voice_client (self ):
162- if self .guild is None :
165+ def voice_client (self ) -> Optional [ VoiceProtocol ] :
166+ if self .interaction . guild is None :
163167 return None
164168
165- return self .guild .voice_client
169+ return self .interaction . guild .voice_client
166170
167171 @cached_property
168172 def response (self ) -> InteractionResponse :
169173 return self .interaction .response
170174
171175 @property
172- def respond (self ) -> Callable [..., Union [Interaction , WebhookMessage ]]:
176+ def respond (self ) -> Callable [..., Awaitable [ Union [Interaction , WebhookMessage ] ]]:
173177 """Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
174178 or a followup response depending if the interaction has been responded to yet or not."""
175- if not self .response .is_done ():
179+ if not self .interaction . response .is_done ():
176180 return self .interaction .response .send_message # self.response
177181 else :
178182 return self .followup .send # self.send_followup
179183
180184 @property
181- def send_response (self ):
182- if not self .response .is_done ():
185+ def send_response (self ) -> Callable [..., Awaitable [ Interaction ]] :
186+ if not self .interaction . response .is_done ():
183187 return self .interaction .response .send_message
184188 else :
185189 raise RuntimeError (
186190 f"Interaction was already issued a response. Try using { type (self ).__name__ } .send_followup() instead."
187191 )
188192
189193 @property
190- def send_followup (self ):
191- if self .response .is_done ():
194+ def send_followup (self ) -> Callable [..., Awaitable [ WebhookMessage ]] :
195+ if self .interaction . response .is_done ():
192196 return self .followup .send
193197 else :
194198 raise RuntimeError (
195199 f"Interaction was not yet issued a response. Try using { type (self ).__name__ } .respond() first."
196200 )
197201
198202 @property
199- def defer (self ):
203+ def defer (self ) -> Callable [..., Awaitable [ None ]] :
200204 return self .interaction .response .defer
201205
202206 @property
203- def followup (self ):
207+ def followup (self ) -> Webhook :
204208 return self .interaction .followup
205209
206210 async def delete (self ):
207211 """Calls :attr:`~discord.commands.ApplicationContext.respond`.
208212 If the response is done, then calls :attr:`~discord.commands.ApplicationContext.respond` first."""
209- if not self .response .is_done ():
213+ if not self .interaction . response .is_done ():
210214 await self .defer ()
211215
212216 return await self .interaction .delete_original_message ()
213217
214218 @property
215- def edit (self ):
219+ def edit (self ) -> Callable [..., Awaitable [ InteractionMessage ]] :
216220 return self .interaction .edit_original_message
217221
218222 @property
@@ -249,7 +253,7 @@ class AutocompleteContext:
249253
250254 __slots__ = ("bot" , "interaction" , "command" , "focused" , "value" , "options" )
251255
252- def __init__ (self , bot : Bot , interaction : Interaction ) -> None :
256+ def __init__ (self , bot : Bot , interaction : Interaction ):
253257 self .bot = bot
254258 self .interaction = interaction
255259
0 commit comments