Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion discord/ui/modal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
import os
import sys
from itertools import groupby
Expand Down Expand Up @@ -29,6 +30,8 @@ def __init__(self, title: str, custom_id: Optional[str] = None) -> None:
self.title = title
self.children: List[InputText] = []
self.__weights = _ModalWeights(self.children)
loop = asyncio.get_running_loop()
self._stopped: asyncio.Future[bool] = loop.create_future()

async def callback(self, interaction: Interaction):
"""|coro|
Expand All @@ -40,7 +43,7 @@ async def callback(self, interaction: Interaction):
interaction: :class:`~discord.Interaction`
The interaction that submitted the modal dialog.
"""
pass
self.stop()

def to_components(self) -> List[Dict[str, Any]]:
def key(item: InputText) -> int:
Expand Down Expand Up @@ -93,6 +96,15 @@ def remove_item(self, item: InputText):
except ValueError:
pass

def stop(self) -> None:
"""Stops listening to interaction events from the modal dialog."""
if not self._stopped.done():
self._stopped.set_result(True)

async def wait(self) -> bool:
"""Waits for the modal dialog to be submitted."""
return await self._stopped

def to_dict(self):
return {
"title": self.title,
Expand Down