Skip to content

Commit 22a99ee

Browse files
authored
Merge pull request #656 from krittick/actx-responses
Revert behavior change to ApplicationContext.respond, make send_response and send_followup explicit in their usage
2 parents 2d100f2 + 4474a7f commit 22a99ee

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
@@ -37,6 +37,8 @@
3737

3838
from .commands import ApplicationCommand, Option
3939
from ..cog import Cog
40+
from ..webhook import WebhookMessage
41+
from typing import Callable
4042

4143
from ..guild import Guild
4244
from ..interactions import Interaction, InteractionResponse
@@ -54,10 +56,8 @@
5456
else:
5557
P = TypeVar('P')
5658

57-
__all__ = (
58-
"ApplicationContext",
59-
"AutocompleteContext"
60-
)
59+
__all__ = ("ApplicationContext", "AutocompleteContext")
60+
6161

6262
class ApplicationContext(discord.abc.Messageable):
6363
"""Represents a Discord application command interaction context.
@@ -162,35 +162,39 @@ def author(self) -> Optional[Union[Member, User]]:
162162
def voice_client(self):
163163
if self.guild is None:
164164
return None
165-
165+
166166
return self.guild.voice_client
167167

168168
@cached_property
169169
def response(self) -> InteractionResponse:
170170
return self.interaction.response
171171

172172
@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]]:
181174
"""Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
182175
or a followup response depending if the interaction has been responded to yet or not."""
183176
if not self.response.is_done():
184177
return self.interaction.response.send_message # self.response
185178
else:
186179
return self.followup.send # self.send_followup
187180

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+
188190
@property
189191
def send_followup(self):
190192
if self.response.is_done():
191193
return self.followup.send
192194
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+
)
194198

195199
@property
196200
def defer(self):
@@ -217,7 +221,7 @@ def cog(self) -> Optional[Cog]:
217221
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
218222
if self.command is None:
219223
return None
220-
224+
221225
return self.command.cog
222226

223227

@@ -231,7 +235,7 @@ class AutocompleteContext:
231235
Attributes
232236
-----------
233237
bot: :class:`.Bot`
234-
The bot that the command belongs to.
238+
The bot that the command belongs to.
235239
interaction: :class:`.Interaction`
236240
The interaction object that invoked the autocomplete.
237241
command: :class:`.ApplicationCommand`
@@ -245,7 +249,7 @@ class AutocompleteContext:
245249
"""
246250

247251
__slots__ = ("bot", "interaction", "command", "focused", "value", "options")
248-
252+
249253
def __init__(self, bot: Bot, interaction: Interaction) -> None:
250254
self.bot = bot
251255
self.interaction = interaction
@@ -260,5 +264,5 @@ def cog(self) -> Optional[Cog]:
260264
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
261265
if self.command is None:
262266
return None
263-
267+
264268
return self.command.cog

0 commit comments

Comments
 (0)