Basic interaction autocomplete support
This commit is contained in:
parent
e99ee71233
commit
5bb88062fa
@ -529,6 +529,7 @@ class InteractionType(Enum):
|
||||
ping = 1
|
||||
application_command = 2
|
||||
component = 3
|
||||
application_command_autocomplete = 4
|
||||
|
||||
|
||||
class InteractionResponseType(Enum):
|
||||
@ -539,6 +540,7 @@ class InteractionResponseType(Enum):
|
||||
deferred_channel_message = 5 # (with source)
|
||||
deferred_message_update = 6 # for components
|
||||
message_update = 7 # for components
|
||||
application_command_autocomplete_result = 8
|
||||
|
||||
|
||||
class VideoQualityMode(Enum):
|
||||
|
@ -51,6 +51,7 @@ if TYPE_CHECKING:
|
||||
|
||||
from .types.interactions import (
|
||||
Interaction as InteractionPayload,
|
||||
ApplicationCommandOptionChoice,
|
||||
InteractionData,
|
||||
)
|
||||
from .guild import Guild
|
||||
@ -632,6 +633,43 @@ class InteractionResponse:
|
||||
|
||||
self.responded_at = utils.utcnow()
|
||||
|
||||
async def autocomplete_result(self, choices: List[ApplicationCommandOptionChoice]):
|
||||
"""|coro|
|
||||
|
||||
Responds to this autocomplete interaction with the resulting choices.
|
||||
This should rarely be used.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
choices: List[Dict[:class:`str`, :class:`str`]]
|
||||
The choices to be shown in the autocomplete UI of the user.
|
||||
Must be a list of dictionaries with the ``name`` and ``value`` keys.
|
||||
|
||||
Raises
|
||||
-------
|
||||
HTTPException
|
||||
Responding to the interaction failed.
|
||||
InteractionResponded
|
||||
This interaction has already been responded to before.
|
||||
"""
|
||||
if self.is_done():
|
||||
raise InteractionResponded(self._parent)
|
||||
|
||||
parent = self._parent
|
||||
if parent.type is not InteractionType.application_command_autocomplete:
|
||||
return
|
||||
|
||||
adapter = async_context.get()
|
||||
await adapter.create_interaction_response(
|
||||
parent.id,
|
||||
parent.token,
|
||||
session=parent._session,
|
||||
type=InteractionResponseType.application_command_autocomplete_result.value,
|
||||
data={"choices": choices},
|
||||
)
|
||||
|
||||
self.responded_at = utils.utcnow()
|
||||
|
||||
|
||||
class _InteractionMessageState:
|
||||
__slots__ = ("_parent", "_interaction")
|
||||
|
Loading…
x
Reference in New Issue
Block a user