hikari.impl.interaction_server
#
Standard implementation of a REST based interactions server.
InteractionServer #
InteractionServer(*, dumps: JSONEncoder = data_binding.default_json_dumps, entity_factory: EntityFactory, executor: Optional[Executor] = None, loads: JSONDecoder = data_binding.default_json_loads, rest_client: RESTClient, public_key: Optional[bytes] = None)
Bases: InteractionServer
Standard implementation of hikari.api.interaction_server.InteractionServer
.
PARAMETER | DESCRIPTION |
---|---|
entity_factory | The entity factory instance this server should use. TYPE: |
dumps | The JSON encoder this server should use. TYPE: |
loads | The JSON decoder this server should use. TYPE: |
public_key | The public key this server should use for verifying request payloads from Discord. If left as |
rest_client | The client this should use for making REST requests. TYPE: |
aiohttp_hook async
#
Handle an AIOHTTP interaction request.
This method handles aiohttp specific detail before calling hikari.impl.interaction_server.InteractionServer.on_interaction
with the data extracted from the request if it can and handles building an aiohttp response.
PARAMETER | DESCRIPTION |
---|---|
request | The received request. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Response | The aiohttp response. |
get_listener #
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 async
#
Handle an interaction received from Discord as a REST server.
Note
If this server instance is alive then this will be called internally by the server but if the instance isn't alive then this may still be called externally to trigger interaction dispatch.
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 #
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 |
start async
#
start(backlog: int = 128, host: Optional[Union[str, Sequence[str]]] = None, port: Optional[int] = None, path: Optional[str] = None, reuse_address: Optional[bool] = None, reuse_port: Optional[bool] = None, socket: Optional[socket] = None, shutdown_timeout: float = 60.0, ssl_context: Optional[SSLContext] = None) -> None
Start the bot and wait for the internal server to startup then return.
Note
For more information on the other parameters such as defaults see AIOHTTP's documentation.
PARAMETER | DESCRIPTION |
---|---|
backlog | The number of unaccepted connections that the system will allow before refusing new connections. TYPE: |
host | TCP/IP host or a sequence of hosts for the HTTP server. |
port | TCP/IP port for the HTTP server. |
path | File system path for HTTP server unix domain socket. |
reuse_address | Tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire. |
reuse_port | Tells the kernel to allow this endpoint to be bound to the same port as other existing endpoints are also bound to. |
socket | A pre-existing socket object to accept connections on. |
shutdown_timeout | A delay to wait, in seconds, for graceful server shutdown before forcefully disconnecting all open client sockets. TYPE: |
ssl_context | SSL context for HTTPS servers. TYPE: |