Clients#
Client#
- asyncclose
- asynccreate
- defdispatch
- @event
- asyncfetch_channel
- asyncfetch_server
- asyncfetch_user
- defget_auth
- defget_channel
- defget_server
- defget_user
- defis_closed
- asynclogin
- asyncon_error
- defrun
- asyncstart
- defwait_for
- asyncwait_until_ready
- 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.
- 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.
- 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.
- 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_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]
- 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.
- 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.
- 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.
- 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 orconnect()
+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.