Skip to content

Commit b5f2187

Browse files
committed
revert behavior change to actx.respond, make send_response and send_follow explicit in their usage
1 parent 51dd856 commit b5f2187

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

discord/commands/context.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
from .commands import ApplicationCommand, Option
3737
from ..cog import Cog
38+
from ..webhook import Webhook
39+
from typing import Callable
3840

3941
from ..guild import Guild
4042
from ..interactions import Interaction, InteractionResponse
@@ -43,10 +45,8 @@
4345
from ..user import User
4446
from ..utils import cached_property
4547

46-
__all__ = (
47-
"ApplicationContext",
48-
"AutocompleteContext"
49-
)
48+
__all__ = ("ApplicationContext", "AutocompleteContext")
49+
5050

5151
class ApplicationContext(discord.abc.Messageable):
5252
"""Represents a Discord application command interaction context.
@@ -125,35 +125,39 @@ def author(self) -> Optional[Union[Member, User]]:
125125
def voice_client(self):
126126
if self.guild is None:
127127
return None
128-
128+
129129
return self.guild.voice_client
130130

131131
@cached_property
132132
def response(self) -> InteractionResponse:
133133
return self.interaction.response
134134

135135
@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]]:
144137
"""Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
145138
or a followup response depending if the interaction has been responded to yet or not."""
146139
if not self.response.is_done():
147140
return self.interaction.response.send_message # self.response
148141
else:
149142
return self.followup.send # self.send_followup
150143

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+
151153
@property
152154
def send_followup(self):
153155
if self.response.is_done():
154156
return self.followup.send
155157
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+
)
157161

158162
@property
159163
def defer(self):
@@ -180,7 +184,7 @@ def cog(self) -> Optional[Cog]:
180184
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
181185
if self.command is None:
182186
return None
183-
187+
184188
return self.command.cog
185189

186190

@@ -194,7 +198,7 @@ class AutocompleteContext:
194198
Attributes
195199
-----------
196200
bot: :class:`.Bot`
197-
The bot that the command belongs to.
201+
The bot that the command belongs to.
198202
interaction: :class:`.Interaction`
199203
The interaction object that invoked the autocomplete.
200204
command: :class:`.ApplicationCommand`
@@ -208,7 +212,7 @@ class AutocompleteContext:
208212
"""
209213

210214
__slots__ = ("bot", "interaction", "command", "focused", "value", "options")
211-
215+
212216
def __init__(self, bot: Bot, interaction: Interaction) -> None:
213217
self.bot = bot
214218
self.interaction = interaction
@@ -223,5 +227,5 @@ def cog(self) -> Optional[Cog]:
223227
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
224228
if self.command is None:
225229
return None
226-
230+
227231
return self.command.cog

0 commit comments

Comments
 (0)