hikari.api.interaction_server
#
Provides an interface for Interaction REST server API implementations to follow.
ListenerT module-attribute
#
ListenerT = Union[Callable[['_InteractionT_co'], Awaitable['_ResponseT_co']], Callable[['_InteractionT_co'], AsyncGenerator['_ResponseT_co', None]]]
Type hint of a Interaction server's listener callback.
This should be an async callback which takes in one positional argument which subclasses hikari.interactions.base_interactions.PartialInteraction
and may return an instance of the relevant hikari.api.special_endpoints.InteractionResponseBuilder
subclass for the provided interaction type which will instruct the server on how to respond.
Note
For the standard implementations of hikari.api.special_endpoints.InteractionResponseBuilder
see hikari.impl.special_endpoints
.
InteractionServer #
Bases: ABC
Interface for an implementation of an interactions compatible REST server.
get_listener abstractmethod
#
get_listener(interaction_type: type[_InteractionT_co]) -> Optional[ListenerT[_InteractionT_co, InteractionResponseBuilder]]
Get the listener registered for an interaction.
PARAMETER | DESCRIPTION |
---|---|
interaction_type | Type of the interaction to get the registered listener for. TYPE: |
RETURNS | DESCRIPTION |
---|---|
typing.Optional[ListenersT[hikari.interactions.base_interactions.PartialInteraction, hikari.api.special_endpoints.InteractionResponseBuilder] | The callback registered for the provided interaction type if found, else |
on_interaction abstractmethod
async
#
Handle an interaction received from Discord as a REST server.
PARAMETER | DESCRIPTION |
---|---|
body | The interaction payload. TYPE: |
signature | Value of the TYPE: |
timestamp | Value of the TYPE: |
RETURNS | DESCRIPTION |
---|---|
Response | Instructions on how the REST server calling this should respond to the interaction request. |
set_listener abstractmethod
#
set_listener(interaction_type: type[_InteractionT_co], listener: Optional[ListenerT[_InteractionT_co, InteractionResponseBuilder]], /, *, replace: bool = False) -> None
Set the listener callback for this interaction server.
PARAMETER | DESCRIPTION |
---|---|
interaction_type | The type of interaction this listener should be registered for. TYPE: |
listener | The asynchronous listener callback to set or An asynchronous listener can be either a normal coroutine or an async generator which should yield exactly once. This allows sending an initial response to the request, while still later executing further logic. TYPE: |
replace | Whether this call should replace the previously set listener or not. TYPE: |
RAISES | DESCRIPTION |
---|---|
TypeError | If |
Response #
Bases: Protocol
Protocol of the data returned by hikari.api.interaction_server.InteractionServer.on_interaction
.
This is used to instruct lower-level REST server logic on how it should respond.
content_type property
#
Content type of the response's payload, if applicable.
files property
#
files: Sequence[Resource[AsyncReader]]
Up to 10 files that should be included alongside a JSON response.
headers property
#
headers: Optional[MutableMapping[str, str]]
Headers that should be added to the response if applicable.
status_code property
#
status_code: int
Status code that should be used to respond.
For more information see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status.