Client is the central entry point of the library. It holds the cache, REST client, WebSocket connection, and event handlers.
ClientOptions
Passed toClient::new(options).
CacheSizeLimits
When a limit is exceeded, the oldest entries are evicted automatically after each
GUILD_CREATE. If a limit is None, the cache is unbounded.Client
Public fields
Methods
Client::new
login is called.
on
serde_json::Value without type information. String constants for event names are available via Events::MESSAGE_CREATE, etc.
Multiple handlers can be registered for the same event - all are called in order.
Example
Example
on_typed
DispatchEvent - an enum with concrete variants for each event. This is the preferred way to handle events.
Example
Example
The closure must return
Box::pin(async move { ... }). All values used inside must be cloned before entering the closure, as it is called repeatedly.login
destroy is called.
user
READY event. Returns None before login.
is_ready / ready_at
is_ready - true after READY is received and (if wait_for_guilds: true) all GUILD_CREATE events have been processed.
ready_at - the instant the ready flag was set.
send_to_gateway / send_to_shard
send_to_gateway broadcasts to all shards. send_to_shard targets a specific shard.
Example: manually update presence
Example: manually update presence
create_message_collector / create_reaction_collector
fetch_instance
GET /instance).
destroy
login will return or error out.
Managers
Managers are thin wrappers that combine cache and REST. They are constructed on the fly from references to client fields. They are not stored as fields onClient - create them right before use.
GuildManager
ChannelManager
UsersManager
Error handling
All async client methods returncrate::Result<T>, where Error is:
