Bot API Reference

Client

class shinkei.ext.bot.BotClient
add_handler(handler)

Events are now handled by bot listeners so this method now raises a NotImplementedError.

remove_handler(handler_name)

Events are now handled by bot listeners so this method now raises a NotImplementedError.

await wait_for(event, *, timeout=None, check=None)

Proxy to discord.Client.wait_for().

await broadcast(data, *, target, nonce=None)

Send data to all clients which matches the predicates of the target query.

Restricted clients cannot use this method.

Parameters
  • data (Union[str, int, float, list, dict]) – The data to send. Must be JSON serializable.

  • target (QueryBuilder) – The query that is used to match the clients.

  • nonce – A value used to identify the data sent.

Raises

ShinkeiWSException – The client is restricted.

await close()

Close the connection to singyeong.

Run this when cleaning up.

await discover(tags)

Discover an application id by it’s clients tags.

Parameters

tags (list) – The list of tags an application client must have to match

Returns

A list of application ids matching.

Return type

list

Raises

TypeError – The tags argument wasn’t a list.

is_closed

Whether or not the client is closed.

Type

bool

latency

The latency, is seconds, between heartbeats.

Type

float

await proxy_request(method, route, *, target, body=None, headers=None)

Make a proxy HTTP request to a client.

Parameters
  • method (str) – The HTTP method to use. Supports only POST, PATCH, PUT, DELETE, MOVE, GET and HEAD.

  • route (str) – The route to make the request to.

  • body (Optional[Union[str, dict, list]]) – The request body, silently ignored in GET and HEAD. If none is provided but the method requires one an empty string will be sent.

  • headers (Optional[Dict[str, str]]) – The request headers.

  • target (QueryBuilder) – The query that is used to match the client.

Returns

The HTTP response.

Return type

Union[str, dict, list]

Raises
await send(data, *, target, nonce=None)

Send data to a client which matches the predicates of the target query.

Restricted clients cannot use this method.

Parameters
  • data (Union[str, int, float, list, dict]) – The data to send. Must be JSON serializable.

  • target (QueryBuilder) – The query that is used to match the client.

  • nonce – A value used to identify the data sent.

Raises

ShinkeiWSException – The client is restricted.

stream(event, *, timeout=None, check=None, limit=None)

Return an async iterator which waits until an event is dispatched before continuing the iterations.

Parameters
  • event (str) – Same as Client.wait_for().

  • timeout (Optional[Union[int, float]]) – Same as Client.wait_for().

  • check (Optional[Callable[…, bool]]) – Same as Client.wait_for().

  • limit (Optional[int]) – The maximum amount of iteration before the iterator stops. By default it never does.

Yields

Any – The return value of the event.

await update_metadata(data, *, cache=True)

Update metadata on singyeong.

The data is not consistent between server restarts but if cache is set to True then it will persist between reconnects.

Parameters
  • data (Dict[str, Union[str, int, float, list, VersionMetadata]]) – The metadata to update. Keys cannot be one of ip, restricted, encoding or last_heartbeat_time.

  • cache (Optional[bool]) – Whether or not to cache the metadata and send it back on reconnects. Defaults to True.

Raises

ShinkeiWSException – The metadata structure was invalid or a restricted key was used.