hikari.api.interaction_server#
Provides an interface for Interaction REST server API implementations to follow.
Module Contents#
- class hikari.api.interaction_server.InteractionServer[source]#
Bases:
abc.ABC
Interface for an implementation of an interactions compatible REST server.
- abstract get_listener(interaction_type, /)[source]#
- abstract get_listener(interaction_type: Type[hikari.interactions.component_interactions.ComponentInteraction], /) ListenerT[hikari.interactions.component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilder] | None
- abstract get_listener(interaction_type: Type[hikari.interactions.command_interactions.AutocompleteInteraction], /) ListenerT[hikari.interactions.command_interactions.AutocompleteInteraction, hikari.api.special_endpoints.InteractionAutocompleteBuilder] | None
- abstract get_listener(interaction_type: Type[hikari.interactions.modal_interactions.ModalInteraction], /) ListenerT[hikari.interactions.modal_interactions.ModalInteraction, _MessageResponseBuilderT] | None
- abstract get_listener(interaction_type: Type[_InteractionT_co], /) ListenerT[_InteractionT_co, hikari.api.special_endpoints.InteractionResponseBuilder] | None
Get the listener registered for an interaction.
- Parameters:
- interaction_type
typing.Type
[hikari.interactions.base_interactions.PartialInteraction
] Type of the interaction to get the registered listener for.
- interaction_type
- Returns:
typing.Optional
[ListenersT
[hikari.interactions.base_interactions.PartialInteraction
,hikari.api.special_endpoints.InteractionResponseBuilder
]The callback registered for the provided interaction type if found, else
None
.
- abstract async on_interaction(body, signature, timestamp)[source]#
Handle an interaction received from Discord as a REST server.
- Parameters:
- Returns:
Response
Instructions on how the REST server calling this should respond to the interaction request.
- abstract set_listener(interaction_type, listener, /, *, replace=False)[source]#
- abstract set_listener(interaction_type: Type[hikari.interactions.component_interactions.ComponentInteraction], listener: ListenerT[hikari.interactions.component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilder] | None, /, *, replace: bool = False) None
- abstract set_listener(interaction_type: Type[hikari.interactions.command_interactions.AutocompleteInteraction], listener: ListenerT[hikari.interactions.command_interactions.AutocompleteInteraction, hikari.api.special_endpoints.InteractionAutocompleteBuilder] | None, /, *, replace: bool = False) None
- abstract set_listener(interaction_type: Type[hikari.interactions.modal_interactions.ModalInteraction], listener: ListenerT[hikari.interactions.modal_interactions.ModalInteraction, _MessageResponseBuilderT] | None, /, *, replace: bool = False) None
Set the listener callback for this interaction server.
- Parameters:
- interaction_type
typing.Type
[hikari.interactions.base_interactions.PartialInteraction
] The type of interaction this listener should be registered for.
- listener
typing.Optional
[ListenerT
[hikari.interactions.base_interactions.PartialInteraction
,hikari.api.special_endpoints.InteractionResponseBuilder
]] The asynchronous listener callback to set or
None
to unset the previous listener.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.
- interaction_type
- Other Parameters:
- replacebool
Whether this call should replace the previously set listener or not. This call will raise a
ValueError
if set toFalse
when a listener is already set.
- Raises:
- class hikari.api.interaction_server.Response[source]#
Bases:
Protocol
Protocol of the data returned by
InteractionServer.on_interaction
.This is used to instruct lower-level REST server logic on how it should respond.
- abstract property content_type: str | None[source]#
Content type of the response’s payload, if applicable.
- abstract property files: Sequence[hikari.files.Resource[hikari.files.AsyncReader]][source]#
Up to 10 files that should be included alongside a JSON response.
- abstract property headers: MutableMapping[str, str] | None[source]#
Headers that should be added to the response if applicable.
- abstract property status_code: int[source]#
Status code that should be used to respond.
For more information see <https://developer.mozilla.org/en-US/docs/Web/HTTP/Status>.
- hikari.api.interaction_server.ListenerT[source]#
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 relevanthikari.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
seehikari.impl.special_endpoints
.