Skip to content

Commit 768dc66

Browse files
JustaSqu1dLulalabyplun1331
authored
Rework ApplicationContext Documentation (#1452)
Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: plun1331 <[email protected]>
1 parent 5a42fff commit 768dc66

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

discord/commands/context.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from typing import TYPE_CHECKING, Dict, List, Optional, TypeVar, Union
2828

2929
import discord.abc
30-
from discord.interactions import InteractionMessage
30+
from discord.interactions import InteractionMessage, InteractionResponse, Interaction
31+
from discord.webhook.async_ import Webhook
3132

3233
if TYPE_CHECKING:
3334
from typing_extensions import ParamSpec
@@ -137,26 +138,33 @@ async def invoke(
137138

138139
@cached_property
139140
def channel(self) -> Optional[InteractionChannel]:
141+
"""Union[:class:`abc.GuildChannel`, :class:`PartialMessageable`, :class:`Thread`]:
142+
Returns the channel associated with this context's command. Shorthand for :attr:`.Interaction.channel`."""
140143
return self.interaction.channel
141144

142145
@cached_property
143146
def channel_id(self) -> Optional[int]:
147+
""":class:`int`: Returns the ID of the channel associated with this context's command. Shorthand for :attr:`.Interaction.channel.id`."""
144148
return self.interaction.channel_id
145149

146150
@cached_property
147151
def guild(self) -> Optional[Guild]:
152+
"""Optional[:class:`.Guild`]: Returns the guild associated with this context's command. Shorthand for :attr:`.Interaction.guild`."""
148153
return self.interaction.guild
149154

150155
@cached_property
151156
def guild_id(self) -> Optional[int]:
157+
""":class:`int`: Returns the ID of the guild associated with this context's command. Shorthand for :attr:`.Interaction.guild.id`."""
152158
return self.interaction.guild_id
153159

154160
@cached_property
155161
def locale(self) -> Optional[str]:
162+
""":class:`str`: Returns the locale of the guild associated with this context's command. Shorthand for :attr:`.Interaction.locale`."""
156163
return self.interaction.locale
157164

158165
@cached_property
159166
def guild_locale(self) -> Optional[str]:
167+
""":class:`str`: Returns the locale of the guild associated with this context's command. Shorthand for :attr:`.Interaction.guild_locale`."""
160168
return self.interaction.guild_locale
161169

162170
@cached_property
@@ -165,27 +173,35 @@ def app_permissions(self) -> Permissions:
165173

166174
@cached_property
167175
def me(self) -> Optional[Union[Member, ClientUser]]:
176+
"""Union[:class:`.Member`, :class:`.ClientUser`]:
177+
Similar to :attr:`.Guild.me` except it may return the :class:`.ClientUser` in private message
178+
message contexts, or when :meth:`Intents.guilds` is absent.
179+
"""
168180
return self.interaction.guild.me if self.interaction.guild is not None else self.bot.user
169181

170182
@cached_property
171183
def message(self) -> Optional[Message]:
184+
"""Optional[:class:`.Message`]: Returns the message sent with this context's command. Shorthand for :attr:`.Interaction.message`, if applicable."""
172185
return self.interaction.message
173186

174187
@cached_property
175188
def user(self) -> Optional[Union[Member, User]]:
189+
"""Union[:class:`.Member`, :class:`.User`]: Returns the user that sent this context's command. Shorthand for :attr:`.Interaction.user`."""
176190
return self.interaction.user
177191

178192
author: Optional[Union[Member, User]] = user
179193

180194
@property
181195
def voice_client(self) -> Optional[VoiceProtocol]:
196+
"""Optional[:class:`.VoiceProtocol`]: Returns the voice client associated with this context's command. Shorthand for :attr:`.Interaction.guild.voice_client`, if applicable."""
182197
if self.interaction.guild is None:
183198
return None
184199

185200
return self.interaction.guild.voice_client
186201

187202
@cached_property
188203
def response(self) -> InteractionResponse:
204+
""":class:`.InteractionResponse`: Returns the response object associated with this context's command. Shorthand for :attr:`.Interaction.response`."""
189205
return self.interaction.response
190206

191207
@property
@@ -222,8 +238,8 @@ def unselected_options(self) -> Optional[List[Option]]:
222238
return None
223239

224240
@property
241+
@discord.utils.copy_doc(InteractionResponse.send_modal)
225242
def send_modal(self) -> Callable[..., Awaitable[Interaction]]:
226-
"""Sends a modal dialog to the user who invoked the interaction."""
227243
return self.interaction.response.send_modal
228244

229245
async def respond(self, *args, **kwargs) -> Union[Interaction, WebhookMessage]:
@@ -246,6 +262,7 @@ async def respond(self, *args, **kwargs) -> Union[Interaction, WebhookMessage]:
246262
return await self.followup.send(*args, **kwargs)
247263

248264
@property
265+
@discord.utils.copy_doc(InteractionResponse.send_message)
249266
def send_response(self) -> Callable[..., Awaitable[Interaction]]:
250267
if not self.interaction.response.is_done():
251268
return self.interaction.response.send_message
@@ -255,6 +272,7 @@ def send_response(self) -> Callable[..., Awaitable[Interaction]]:
255272
)
256273

257274
@property
275+
@discord.utils.copy_doc(Webhook.send)
258276
def send_followup(self) -> Callable[..., Awaitable[WebhookMessage]]:
259277
if self.interaction.response.is_done():
260278
return self.followup.send
@@ -264,11 +282,13 @@ def send_followup(self) -> Callable[..., Awaitable[WebhookMessage]]:
264282
)
265283

266284
@property
285+
@discord.utils.copy_doc(InteractionResponse.defer)
267286
def defer(self) -> Callable[..., Awaitable[None]]:
268287
return self.interaction.response.defer
269288

270289
@property
271290
def followup(self) -> Webhook:
291+
""":class:`Webhook`: Returns the follow up webhook for follow up interactions."""
272292
return self.interaction.followup
273293

274294
async def delete(self, *, delay: Optional[float] = None) -> None:
@@ -296,6 +316,7 @@ async def delete(self, *, delay: Optional[float] = None) -> None:
296316
return await self.interaction.delete_original_message(delay=delay)
297317

298318
@property
319+
@discord.utils.copy_doc(Interaction.edit_original_message)
299320
def edit(self) -> Callable[..., Awaitable[InteractionMessage]]:
300321
return self.interaction.edit_original_message
301322

0 commit comments

Comments
 (0)