mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-11 04:17:58 +00:00
Add missing generic parameters on various Interaction parameters
This commit is contained in:
parent
c677ad0312
commit
bbba8c650f
@ -40,7 +40,6 @@ from typing import (
|
|||||||
Sequence,
|
Sequence,
|
||||||
Set,
|
Set,
|
||||||
Tuple,
|
Tuple,
|
||||||
TypeVar,
|
|
||||||
Union,
|
Union,
|
||||||
overload,
|
overload,
|
||||||
)
|
)
|
||||||
@ -63,11 +62,12 @@ from .translator import Translator, locale_str
|
|||||||
from ..errors import ClientException, HTTPException
|
from ..errors import ClientException, HTTPException
|
||||||
from ..enums import AppCommandType, InteractionType
|
from ..enums import AppCommandType, InteractionType
|
||||||
from ..utils import MISSING, _get_as_snowflake, _is_submodule
|
from ..utils import MISSING, _get_as_snowflake, _is_submodule
|
||||||
|
from .._types import ClientT
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..types.interactions import ApplicationCommandInteractionData, ApplicationCommandInteractionDataOption
|
from ..types.interactions import ApplicationCommandInteractionData, ApplicationCommandInteractionDataOption
|
||||||
from ..interactions import Interaction
|
from ..interactions import Interaction
|
||||||
from ..client import Client
|
|
||||||
from ..abc import Snowflake
|
from ..abc import Snowflake
|
||||||
from .commands import ContextMenuCallback, CommandCallback, P, T
|
from .commands import ContextMenuCallback, CommandCallback, P, T
|
||||||
|
|
||||||
@ -78,8 +78,6 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
__all__ = ('CommandTree',)
|
__all__ = ('CommandTree',)
|
||||||
|
|
||||||
ClientT = TypeVar('ClientT', bound='Client')
|
|
||||||
|
|
||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -773,7 +771,7 @@ class CommandTree(Generic[ClientT]):
|
|||||||
for key in remove:
|
for key in remove:
|
||||||
del mapping[key]
|
del mapping[key]
|
||||||
|
|
||||||
async def on_error(self, interaction: Interaction, error: AppCommandError, /) -> None:
|
async def on_error(self, interaction: Interaction[ClientT], error: AppCommandError, /) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
A callback that is called when any command raises an :exc:`AppCommandError`.
|
A callback that is called when any command raises an :exc:`AppCommandError`.
|
||||||
@ -1076,7 +1074,7 @@ class CommandTree(Generic[ClientT]):
|
|||||||
|
|
||||||
return [AppCommand(data=d, state=self._state) for d in data]
|
return [AppCommand(data=d, state=self._state) for d in data]
|
||||||
|
|
||||||
async def _dispatch_error(self, interaction: Interaction, error: AppCommandError, /) -> None:
|
async def _dispatch_error(self, interaction: Interaction[ClientT], error: AppCommandError, /) -> None:
|
||||||
command = interaction.command
|
command = interaction.command
|
||||||
interaction.command_failed = True
|
interaction.command_failed = True
|
||||||
try:
|
try:
|
||||||
@ -1085,7 +1083,7 @@ class CommandTree(Generic[ClientT]):
|
|||||||
finally:
|
finally:
|
||||||
await self.on_error(interaction, error)
|
await self.on_error(interaction, error)
|
||||||
|
|
||||||
def _from_interaction(self, interaction: Interaction) -> None:
|
def _from_interaction(self, interaction: Interaction[ClientT]) -> None:
|
||||||
async def wrapper():
|
async def wrapper():
|
||||||
try:
|
try:
|
||||||
await self._call(interaction)
|
await self._call(interaction)
|
||||||
@ -1156,7 +1154,9 @@ class CommandTree(Generic[ClientT]):
|
|||||||
|
|
||||||
return (command, options)
|
return (command, options)
|
||||||
|
|
||||||
async def _call_context_menu(self, interaction: Interaction, data: ApplicationCommandInteractionData, type: int) -> None:
|
async def _call_context_menu(
|
||||||
|
self, interaction: Interaction[ClientT], data: ApplicationCommandInteractionData, type: int
|
||||||
|
) -> None:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
guild_id = _get_as_snowflake(data, 'guild_id')
|
guild_id = _get_as_snowflake(data, 'guild_id')
|
||||||
ctx_menu = self._context_menus.get((name, guild_id, type))
|
ctx_menu = self._context_menus.get((name, guild_id, type))
|
||||||
@ -1195,7 +1195,7 @@ class CommandTree(Generic[ClientT]):
|
|||||||
else:
|
else:
|
||||||
self.client.dispatch('app_command_completion', interaction, ctx_menu)
|
self.client.dispatch('app_command_completion', interaction, ctx_menu)
|
||||||
|
|
||||||
async def interaction_check(self, interaction: Interaction, /) -> bool:
|
async def interaction_check(self, interaction: Interaction[ClientT], /) -> bool:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
A global check to determine if an :class:`~discord.Interaction` should
|
A global check to determine if an :class:`~discord.Interaction` should
|
||||||
@ -1206,7 +1206,7 @@ class CommandTree(Generic[ClientT]):
|
|||||||
"""
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def _call(self, interaction: Interaction) -> None:
|
async def _call(self, interaction: Interaction[ClientT]) -> None:
|
||||||
if not await self.interaction_check(interaction):
|
if not await self.interaction_check(interaction):
|
||||||
interaction.command_failed = True
|
interaction.command_failed = True
|
||||||
return
|
return
|
||||||
|
@ -1161,9 +1161,9 @@ class Client:
|
|||||||
event: Literal['app_command_completion'],
|
event: Literal['app_command_completion'],
|
||||||
/,
|
/,
|
||||||
*,
|
*,
|
||||||
check: Optional[Callable[[Interaction, Union[Command, ContextMenu]], bool]],
|
check: Optional[Callable[[Interaction[Self], Union[Command, ContextMenu]], bool]],
|
||||||
timeout: Optional[float] = None,
|
timeout: Optional[float] = None,
|
||||||
) -> Tuple[Interaction, Union[Command, ContextMenu]]:
|
) -> Tuple[Interaction[Self], Union[Command, ContextMenu]]:
|
||||||
...
|
...
|
||||||
|
|
||||||
# AutoMod
|
# AutoMod
|
||||||
@ -1447,9 +1447,9 @@ class Client:
|
|||||||
event: Literal['interaction'],
|
event: Literal['interaction'],
|
||||||
/,
|
/,
|
||||||
*,
|
*,
|
||||||
check: Optional[Callable[[Interaction], bool]],
|
check: Optional[Callable[[Interaction[Self]], bool]],
|
||||||
timeout: Optional[float] = None,
|
timeout: Optional[float] = None,
|
||||||
) -> Interaction:
|
) -> Interaction[Self]:
|
||||||
...
|
...
|
||||||
|
|
||||||
# Members
|
# Members
|
||||||
|
@ -302,7 +302,7 @@ class Interaction(Generic[ClientT]):
|
|||||||
return tree._get_context_menu(data)
|
return tree._get_context_menu(data)
|
||||||
|
|
||||||
@utils.cached_slot_property('_cs_response')
|
@utils.cached_slot_property('_cs_response')
|
||||||
def response(self) -> InteractionResponse:
|
def response(self) -> InteractionResponse[ClientT]:
|
||||||
""":class:`InteractionResponse`: Returns an object responsible for handling responding to the interaction.
|
""":class:`InteractionResponse`: Returns an object responsible for handling responding to the interaction.
|
||||||
|
|
||||||
A response can only be done once. If secondary messages need to be sent, consider using :attr:`followup`
|
A response can only be done once. If secondary messages need to be sent, consider using :attr:`followup`
|
||||||
@ -548,7 +548,7 @@ class Interaction(Generic[ClientT]):
|
|||||||
return await translator.translate(string, locale=locale, context=context)
|
return await translator.translate(string, locale=locale, context=context)
|
||||||
|
|
||||||
|
|
||||||
class InteractionResponse:
|
class InteractionResponse(Generic[ClientT]):
|
||||||
"""Represents a Discord interaction response.
|
"""Represents a Discord interaction response.
|
||||||
|
|
||||||
This type can be accessed through :attr:`Interaction.response`.
|
This type can be accessed through :attr:`Interaction.response`.
|
||||||
@ -561,8 +561,8 @@ class InteractionResponse:
|
|||||||
'_parent',
|
'_parent',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, parent: Interaction):
|
def __init__(self, parent: Interaction[ClientT]):
|
||||||
self._parent: Interaction = parent
|
self._parent: Interaction[ClientT] = parent
|
||||||
self._response_type: Optional[InteractionResponseType] = None
|
self._response_type: Optional[InteractionResponseType] = None
|
||||||
|
|
||||||
def is_done(self) -> bool:
|
def is_done(self) -> bool:
|
||||||
|
@ -27,6 +27,7 @@ from __future__ import annotations
|
|||||||
from typing import Any, Callable, Coroutine, Dict, Generic, Optional, TYPE_CHECKING, Tuple, Type, TypeVar
|
from typing import Any, Callable, Coroutine, Dict, Generic, Optional, TYPE_CHECKING, Tuple, Type, TypeVar
|
||||||
|
|
||||||
from ..interactions import Interaction
|
from ..interactions import Interaction
|
||||||
|
from .._types import ClientT
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -119,7 +120,7 @@ class Item(Generic[V]):
|
|||||||
"""Optional[:class:`View`]: The underlying view for this item."""
|
"""Optional[:class:`View`]: The underlying view for this item."""
|
||||||
return self._view
|
return self._view
|
||||||
|
|
||||||
async def callback(self, interaction: Interaction) -> Any:
|
async def callback(self, interaction: Interaction[ClientT]) -> Any:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
The callback associated with this UI item.
|
The callback associated with this UI item.
|
||||||
|
@ -31,6 +31,7 @@ from copy import deepcopy
|
|||||||
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, ClassVar, List
|
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, ClassVar, List
|
||||||
|
|
||||||
from ..utils import MISSING, find
|
from ..utils import MISSING, find
|
||||||
|
from .._types import ClientT
|
||||||
from .item import Item
|
from .item import Item
|
||||||
from .view import View
|
from .view import View
|
||||||
|
|
||||||
@ -134,7 +135,7 @@ class Modal(View):
|
|||||||
|
|
||||||
super().__init__(timeout=timeout)
|
super().__init__(timeout=timeout)
|
||||||
|
|
||||||
async def on_submit(self, interaction: Interaction, /) -> None:
|
async def on_submit(self, interaction: Interaction[ClientT], /) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Called when the modal is submitted.
|
Called when the modal is submitted.
|
||||||
@ -146,7 +147,7 @@ class Modal(View):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def on_error(self, interaction: Interaction, error: Exception, /) -> None:
|
async def on_error(self, interaction: Interaction[ClientT], error: Exception, /) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
A callback that is called when :meth:`on_submit`
|
A callback that is called when :meth:`on_submit`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user