Skip to main content
Client is the central entry point of the library. It holds the cache, REST client, WebSocket connection, and event handlers.

ClientOptions

Passed to Client::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

Creates the client. REST is initialized immediately. The WebSocket connection is not established until login is called.

on

Registers a raw event handler by name. Data is delivered as 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.

on_typed

Registers a typed event handler. Receives a DispatchEvent - an enum with concrete variants for each event. This is the preferred way to handle events.
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

Sets the token in REST, connects to Gateway, and starts the WebSocket event loop. Blocks execution until the connection is dropped or destroy is called.

user

Returns the bot’s own user data received in the 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

Sends a raw JSON payload to Gateway. send_to_gateway broadcasts to all shards. send_to_shard targets a specific shard.

create_message_collector / create_reaction_collector

Creates a collector for gathering messages or reactions. See Collectors for details.

fetch_instance

Returns information about the Fluxer instance (GET /instance).

destroy

Terminates the WebSocket connection and resets client state. After calling this, 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 on Client - create them right before use.

GuildManager

ChannelManager

UsersManager

Error handling

All async client methods return crate::Result<T>, where Error is: