Clients#

Client#

class defectio.Client(*, api_url='https://api.revolt.chat', loop=None, **kwargs)[source]#
dispatch(event, *args, **kwargs)[source]#

Dispatch an event

Parameters

event (str) – The event to dispatch.

await on_error(event_method, *args, **kwargs)[source]#

This function is a coroutine. The default error handler provided by the client. By default this prints to sys.stderr however it could be overridden to have a different implementation.

await wait_until_ready()[source]#

This function is a coroutine. Waits until the client’s internal cache is all ready.

wait_for(event, *, check=None, timeout=None)[source]#

Waits for a specific event to be dispatched.

Parameters
  • event (str) – The event to wait for.

  • check (Optional[Callable[..., bool]], optional) – A check to run on the event, by default None

  • timeout (Optional[float], optional) – timeout to wait, by default None

Returns

response from method

Return type

Any

event(coro)[source]#

A decorator that registers an event to listen to.

Example

@client.event
async def on_ready():
    print('Ready!')
Raises

TypeError – The coroutine passed is not actually a coroutine.

property user#

Represents the connected client. None if not logged in.

Type

Optional[ClientUser]

property users#

Returns a list of all the users stored in the internal cache.

Returns

A list of cached users.

Return type

list[User]

property cached_messages#

Read-only list of messages the connected client has cached. .. versionadded:: 1.1

Type

Sequence[Message]

property servers#

Returns a list of all the servers stored in the internal cache.

Returns

A list of cached servers.

Return type

list[Server]

property channels#

Returns a list of all the channels stored in the internal cache.

Returns

[A list of cached channels

Return type

list[Channel]

get_auth()[source]#

Returns the Auth object used for logging in.

get_channel(channel_id)[source]#

Get a channel with the specified ID from the internal cache.

Parameters

channel_id (str) – The channel ID to look for.

Returns

The requested channel. If not found, returns None.

Return type

Optional[Channel]

get_server(server_id)[source]#

Get a server with the specified ID from the internal cache.

Parameters

server_id (str) – The server ID to look for.

Returns

The requested server. If not found, returns None.

Return type

Optional[Server]

get_user(user_id)[source]#

Get a user with the specified ID from the internal cache.

Parameters

user_id (str) – The user ID to look for.

Returns

The requested user. If not found, returns None.

Return type

Optional[User]

await fetch_channel(channel_id)[source]#

Fetches a channel from revolt bypassing the internal cache.

This should be used if you beleive the cache may be stale but it is recommended to use get_channel() instead.

Parameters

channel_id (str) – The channel ID to look for.

Returns

The requested channel. If not found, returns None.

Return type

Optional[Channel]

await fetch_server(server_id)[source]#

Fetches a server from revolution bypassing the internal cache.

This should be used if you beleive the cache may be stale but it is recommended to use get_server() instead.

Parameters

server_id (str) – The server ID to look for.

Returns

The requested server. If not found, returns None.

Return type

Optional[Server]

await fetch_user(user_id)[source]#

Fetches a user from revolution bypassing the internal cache.

This should be used if you beleive the cache may be stale but it is recommended to use get_user() instead.

Parameters

user_id (str) – The user ID to look for.

Returns

The requested user. If not found, returns None.

Return type

Optional[User]

is_closed()[source]#

Indicates if the websocket connection is closed.

await close()[source]#

This function is a coroutine. Closes the connection to revolt.

await create()[source]#

This function is a coroutine. Creates the client with the cache, websocket and http client.

await login(token, bot=True)[source]#

This function is a coroutine. Logs in using the token provided as a bot.

Parameters

token (str) – The authentication token.

await start(*, token=None, bot=True)[source]#

This function is a coroutine. Creates a client and logs the user in.

Parameters
  • token (Optional[str]) – The Revolt API token.

  • session_token (Optional[str]) – The Revolt session ID of a user

  • user_id (Optional[str]) – The ID of the user which th session token belongs to

run(token=None, *, bot=True)[source]#

A blocking call that abstracts away the event loop initialisation from you.

If you want more control over the event loop then this function should not be used. Use start() coroutine or connect() + login().

Roughly Equivalent to:

try:
    loop.run_until_complete(start(*args, **kwargs))
except KeyboardInterrupt:
    loop.run_until_complete(close())
    # cancel all tasks lingering
finally:
    loop.close()

Warning

This function must be the last function to call due to the fact that it is blocking. That means that registration of events or anything being called after this function call will not execute until it returns.

Parameters
  • token (Optional[str]) – The authentication token of the bot to login.

  • bot (bool) – Indicates if the client is a bot account. Defaults to True.