Add support for Modal Interactions

This commit is contained in:
Josh
2022-02-20 19:57:44 +10:00
committed by GitHub
parent 964ca0a6f1
commit 19c6687b55
13 changed files with 679 additions and 17 deletions

View File

@@ -60,6 +60,7 @@ if TYPE_CHECKING:
from aiohttp import ClientSession
from .embeds import Embed
from .ui.view import View
from .ui.modal import Modal
from .channel import VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel, PartialMessageable
from .threads import Thread
@@ -628,6 +629,41 @@ class InteractionResponse:
self._responded = True
async def send_modal(self, modal: Modal, /):
"""|coro|
Responds to this interaction by sending a modal.
Parameters
-----------
modal: :class:`~discord.ui.Modal`
The modal to send.
Raises
-------
HTTPException
Sending the modal failed.
InteractionResponded
This interaction has already been responded to before.
"""
if self._responded:
raise InteractionResponded(self._parent)
parent = self._parent
adapter = async_context.get()
params = interaction_response_params(InteractionResponseType.modal.value, modal.to_dict())
await adapter.create_interaction_response(
parent.id,
parent.token,
session=parent._session,
params=params,
)
self._parent._state.store_view(modal)
self._responded = True
class _InteractionMessageState:
__slots__ = ('_parent', '_interaction')