hikari.api.interaction_server#

Provides an interface for Interaction REST server API implementations to follow.

Module Contents#

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 relevant hikari.api.special_endpoints.InteractionResponseBuilder subclass for the provided interaction type which will instruct the server on how to respond.

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: Optional[str][source]#

Content type of the response’s payload, if applicable.

abstract property charset: Optional[str][source]#

Charset 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: Optional[MutableMapping[str, str]][source]#

Headers that should be added to the response if applicable.

abstract property payload: Optional[bytes][source]#

Payload to provide in the response.

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>.

class hikari.api.interaction_server.InteractionServer[source]#

Bases: abc.ABC

Interface for an implementation of an interactions compatible REST server.

abstract async on_interaction(body, signature, timestamp)[source]#

Handle an interaction received from Discord as a REST server.

Parameters
bodybytes

The interaction payload.

signaturebytes

Value of the "X-Signature-Ed25519" header used to verify the body.

timestampbytes

Value of the "X-Signature-Timestamp" header used to verify the body.

Returns
Response

Instructions on how the REST server calling this should respond to the interaction request.

abstract get_listener(interaction_type, /)[source]#
abstract get_listener(interaction_type: Type[hikari.interactions.component_interactions.ComponentInteraction], /) Optional[ListenerT[hikari.interactions.component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilder]]
abstract get_listener(interaction_type: Type[hikari.interactions.command_interactions.AutocompleteInteraction], /) Optional[ListenerT[hikari.interactions.command_interactions.AutocompleteInteraction, hikari.api.special_endpoints.InteractionAutocompleteBuilder]]
abstract get_listener(interaction_type: Type[hikari.interactions.modal_interactions.ModalInteraction], /) Optional[ListenerT[hikari.interactions.modal_interactions.ModalInteraction, _MessageResponseBuilderT]]
abstract get_listener(interaction_type: Type[_InteractionT_co], /) Optional[ListenerT[_InteractionT_co, hikari.api.special_endpoints.InteractionResponseBuilder]]

Get the listener registered for an interaction.

Parameters
interaction_typetyping.Type[hikari.interactions.base_interactions.PartialInteraction]

Type of the interaction to get the registered listener for.

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 set_listener(interaction_type, listener, /, *, replace=False)[source]#
abstract set_listener(interaction_type: Type[hikari.interactions.component_interactions.ComponentInteraction], listener: Optional[ListenerT[hikari.interactions.component_interactions.ComponentInteraction, _ModalOrMessageResponseBuilder]], /, *, replace: bool = False) None
abstract set_listener(interaction_type: Type[hikari.interactions.command_interactions.AutocompleteInteraction], listener: Optional[ListenerT[hikari.interactions.command_interactions.AutocompleteInteraction, hikari.api.special_endpoints.InteractionAutocompleteBuilder]], /, *, replace: bool = False) None
abstract set_listener(interaction_type: Type[hikari.interactions.modal_interactions.ModalInteraction], listener: Optional[ListenerT[hikari.interactions.modal_interactions.ModalInteraction, _MessageResponseBuilderT]], /, *, replace: bool = False) None

Set the listener callback for this interaction server.

Parameters
interaction_typetyping.Type[hikari.interactions.base_interactions.PartialInteraction]

The type of interaction this listener should be registered for.

listenertyping.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.

Other Parameters
replacebool

Whether this call should replace the previously set listener or not. This call will raise a ValueError if set to False when a listener is already set.

Raises
TypeError

If replace is False when a listener is already set.