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).
| Field | Type | Default | Description |
|---|---|---|---|
intents | u64 | 0 | Gateway intents. Fluxer does not use intents - always 0. |
presence | Option<GatewayPresenceUpdateSendData> | None | Initial bot presence on connect. |
rest | Option<RestOptions> | None | REST client options. Defaults are used when None. |
gateway_version | Option<String> | None | Gateway version. Defaults to "1" when None. |
wait_for_guilds | bool | false | If true, the Ready event is delayed until all GUILD_CREATE events are received. |
cache | CacheSizeLimits | all None | Per-entity cache size limits. |
CacheSizeLimits
| Field | Type | Description |
|---|---|---|
guilds | Option<usize> | Maximum number of guilds in cache. |
channels | Option<usize> | Maximum number of channels in cache. |
users | Option<usize> | Maximum number of users in cache. |
members | Option<usize> | Maximum number of members (across all guilds) in cache. |
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
| Field | Type | Description |
|---|---|---|
rest | Rest | REST client. Arc-based, cloning is cheap. |
guilds | DashMap<String, Guild> | Guild cache. |
channels | DashMap<String, Channel> | Channel cache. |
users | DashMap<String, User> | User cache. |
members | DashMap<String, DashMap<String, GuildMember>> | Member cache: guild_id → user_id → GuildMember. |
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
| Method | Description |
|---|---|
get(id) | Returns a guild from cache. None if not present. |
fetch(id) | Fetches the guild via REST, updates cache. |
resolve(id) | Returns from cache, falls back to fetch. |
ChannelManager
| Method | Description |
|---|---|
get(id) | Returns a channel from cache. |
fetch(id) | Fetches the channel via REST, updates cache. |
resolve(id) | Cache → REST fallback. |
send(channel_id, body) | Sends a message to a channel without going through the Channel structure. |
fetch_message(channel_id, message_id) | Fetches a message by ID. |
UsersManager
| Method | Description |
|---|---|
get(id) | Returns a user from cache. |
fetch(id) | Fetches the user via REST. |
resolve(id) | Cache → REST fallback. |
fetch_with_profile(id) | Returns ApiProfileResponse - extended profile data. |
Error handling
All async client methods returncrate::Result<T>, where Error is:
| Variant | Description |
|---|---|
Error::ClientNotReady | Method called before login completed. |
Error::InvalidToken | Token rejected by Gateway. |
Error::AlreadyLoggedIn | login called more than once. |
Error::Api(FluxerApiError) | API returned a structured error with code and message. |
Error::Http(HttpError) | HTTP error without a recognized API response body. |
Error::RateLimit(RateLimitError) | Rate limit exhausted after all retry attempts. |
Error::Rest(RestError) | Network or JSON error. |
Error::WebSocket(String) | WebSocket connection error. |
Error::Other(String) | Miscellaneous errors. |
