hikari.api.interaction_server#
Provides an interface for Interaction REST server API implementations to follow.
ListenerT module-attribute #
ListenerT = typing.Union[
typing.Callable[
["_InteractionT_co"],
typing.Awaitable[
typing.Union["_ResponseT_co", None]
],
],
typing.Callable[
["_InteractionT_co"],
typing.AsyncGenerator[
typing.Union["_ResponseT_co", None], 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.
If the callback returns None, an HTTP no-content response will be returned. In this case you should respond to the interaction using the appropriate REST method instead.
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],
) -> (
ListenerT[_InteractionT_co, InteractionResponseBuilder]
| None
)
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[CommandInteraction],
listener: ListenerT[
CommandInteraction, _ModalOrMessageResponseBuilder
]
| None,
/,
*,
replace: bool = False,
) -> None
set_listener(
interaction_type: type[ComponentInteraction],
listener: ListenerT[
ComponentInteraction, _ModalOrMessageResponseBuilder
]
| None,
/,
*,
replace: bool = False,
) -> None
set_listener(
interaction_type: type[AutocompleteInteraction],
listener: ListenerT[
AutocompleteInteraction,
InteractionAutocompleteBuilder,
]
| None,
/,
*,
replace: bool = False,
) -> None
set_listener(
interaction_type: type[ModalInteraction],
listener: ListenerT[
ModalInteraction, _MessageResponseBuilderT
]
| None,
/,
*,
replace: bool = False,
) -> None
set_listener(
interaction_type: type[_InteractionT_co],
listener: ListenerT[
_InteractionT_co, InteractionResponseBuilder
]
| None,
/,
*,
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: str | None
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: MutableMapping[str, str] | None
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.