|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | import datetime
|
2 | 4 | import typing
|
| 5 | +from typing import TYPE_CHECKING |
3 | 6 | from warnings import warn
|
4 | 7 |
|
5 | 8 | import discord
|
|
9 | 12 | from . import error, http, model
|
10 | 13 | from .dpy_overrides import ComponentMessage
|
11 | 14 |
|
| 15 | +if TYPE_CHECKING: # circular import sucks for typehinting |
| 16 | + from . import client |
| 17 | + |
12 | 18 |
|
13 | 19 | class InteractionContext:
|
14 | 20 | """
|
@@ -115,18 +121,21 @@ def channel(self) -> typing.Optional[typing.Union[discord.TextChannel, discord.D
|
115 | 121 | return self.bot.get_channel(self.channel_id)
|
116 | 122 |
|
117 | 123 | @property
|
118 |
| - def voice_client(self): |
| 124 | + def voice_client(self) -> typing.Optional[discord.VoiceProtocol]: |
119 | 125 | """
|
120 | 126 | VoiceClient instance of the command invoke. If the command was invoked in DM, then it is ``None``.
|
121 | 127 | If the bot is not connected to any Voice/Stage channels, then it is ``None``.
|
122 | 128 |
|
| 129 | + :return: Optional[discord.VoiceProtocol] |
123 | 130 | """
|
124 | 131 | return self.guild.voice_client if self.guild else None
|
125 | 132 |
|
126 | 133 | @property
|
127 |
| - def me(self): |
| 134 | + def me(self) -> typing.Union[discord.Member, discord.ClientUser]: |
128 | 135 | """
|
129 | 136 | Similar to :attr:`.Guild.me` except that it may also return the bot user in DM context.
|
| 137 | +
|
| 138 | + :return: Union[discord.Member, discord.ClientUser] |
130 | 139 | """
|
131 | 140 | return self.guild.me if self.guild is not None else self.bot.user
|
132 | 141 |
|
@@ -359,13 +368,24 @@ def __init__(
|
359 | 368 |
|
360 | 369 | super().__init__(_http=_http, _json=_json, _discord=_discord, logger=logger)
|
361 | 370 |
|
| 371 | + @property |
| 372 | + def slash(self) -> client.SlashCommand: |
| 373 | + """ |
| 374 | + Returns the associated SlashCommand object created during Runtime. |
| 375 | +
|
| 376 | + :return: client.SlashCommand |
| 377 | + """ |
| 378 | + return self.bot.slash # noqa |
| 379 | + |
362 | 380 | @property
|
363 | 381 | def cog(self) -> typing.Optional[commands.Cog]:
|
364 | 382 | """
|
365 | 383 | Returns the cog associated with the command invoked, if any.
|
| 384 | +
|
| 385 | + :return: Optional[commands.Cog] |
366 | 386 | """
|
367 | 387 |
|
368 |
| - cmd_obj = self.bot.slash.commands[self.command] # noqa |
| 388 | + cmd_obj = self.slash.commands[self.command] |
369 | 389 |
|
370 | 390 | if isinstance(cmd_obj, (model.CogBaseCommandObject, model.CogSubcommandObject)):
|
371 | 391 | return cmd_obj.cog
|
|
0 commit comments