pub struct ClientBuilder<B: Backend = DashMapBackend> { /* private fields */ }Expand description
Configures and builds a Client. Created by Client::builder.
B is the cache backend (D-172), switched with cache_backend.
discord.js counterpart: ClientOptions.
Implementations§
Source§impl<B: Backend> ClientBuilder<B>
impl<B: Backend> ClientBuilder<B>
Sourcepub const fn intents(self, intents: Intents) -> Self
pub const fn intents(self, intents: Intents) -> Self
Sets the gateway intents — the groups of events to receive (default: none).
Only request what the bot needs. Privileged intents
(Intents::PRIVILEGED) must be enabled in the Developer Portal first.
discord.js counterpart: the intents option of ClientOptions.
Sourcepub fn rest(self, rest: Rest) -> Self
pub fn rest(self, rest: Rest) -> Self
Uses a preconfigured REST client (for example with a proxy or custom timeouts) instead of one built from the token.
discord.js counterpart: the rest option of ClientOptions.
Sourcepub const fn compression(self, compression: Compression) -> Self
pub const fn compression(self, compression: Compression) -> Self
Sets the gateway transport compression (default: zstd-stream when the feature is
enabled).
discord.js counterpart: the ws.compression option of ClientOptions.
Sourcepub fn gateway_url(self, url: impl Into<String>) -> Self
pub fn gateway_url(self, url: impl Into<String>) -> Self
Connects to this gateway URL instead of the one from Get Gateway Bot (useful for proxies and tests).
Get Gateway Bot is still called for Shards::Auto; with a fixed shard count too, the
client does not call it at all and shards identify one at a time (max_concurrency 1).
discord.js counterpart: none (discord.js always asks Get Gateway Bot).
Sourcepub fn shards(self, shards: Shards) -> Self
pub fn shards(self, shards: Shards) -> Self
Sets which shards to run (default Shards::Auto: as many as Discord recommends).
discord.js counterpart: the shards and shardCount options of ClientOptions.
§Panics
Panics on a shard count of 0, or a range that is empty or reaches past total.
§Examples
use djs_rs::{Client, Shards};
// Shards 0–7 of 16 run in this process; another process runs 8–15.
let client = Client::builder("my-token")
.shards(Shards::Range { range: 0..8, total: 16 })
.build();Sourcepub fn cluster(self, assignment: ClusterAssignment) -> Self
pub fn cluster(self, assignment: ClusterAssignment) -> Self
Makes this client the one of a cluster process started by a
ClusterManager (D-300): it runs the assignment’s
shards (Shards::Range), connects to the manager when it logs in, and shuts down
when the manager asks or goes away. Get the assignment from
sharding::process.
The client then does not call Get Gateway Bot: the gateway URL and max_concurrency
come from the manager (D-305, a gateway_url set here still
wins), and its shards wait for their IDENTIFY turns from the manager (D-299).
discord.js counterpart: what new Client() reads from the environment in a shard
process (client.shard).
Sourcepub fn presence(self, presence: UpdatePresence) -> Self
pub fn presence(self, presence: UpdatePresence) -> Self
Sets the presence (status and activities) every shard starts with (default: none, the
bot appears online without an activity). Change it later with Client::set_presence.
discord.js counterpart: the presence client option.
§Examples
use djs_rs::{
Client,
model::gateway::{Activity, Status, payload::UpdatePresence},
};
let client = Client::builder("my-token")
.presence(UpdatePresence::new(Status::Online, [Activity::playing("with Rust")]))
.build();Sourcepub const fn handler_mode(self, mode: HandlerMode) -> Self
pub const fn handler_mode(self, mode: HandlerMode) -> Self
Sets how handlers are executed (default HandlerMode::Concurrent).
discord.js counterpart: none (discord.js runs every listener as its event comes).
Sourcepub fn cache(self, config: CacheConfig) -> Self
pub fn cache(self, config: CacheConfig) -> Self
Gives the client a Cache configured by config (default: no cache, D-170).
The client applies every event to the cache before running its handlers (D-171), and
runs the periodic sweeps of CacheConfig::sweepers while it is logged in. Read it
with Client::cache and Context::cache. What the cache can fill depends on the
intents: members need Intents::GUILD_MEMBERS, presences
Intents::GUILD_PRESENCES, messages Intents::GUILD_MESSAGES or
Intents::DIRECT_MESSAGES, and so on.
discord.js counterpart: the makeCache and sweepers client options. discord.js
always caches; CacheConfig::discord_js caches what it caches by default.
§Examples
use djs_rs::{
Client,
cache::{CacheConfig, Limit, Resource},
model::gateway::Intents,
};
let config = CacheConfig::builder()
.members(Limit::Unlimited)
.messages(Limit::Max(50))
.build();
let client = Client::builder("my-token")
.intents(Intents::GUILDS | Intents::GUILD_MEMBERS | Intents::GUILD_MESSAGES)
.cache(config)
.build();
let cache = client.cache().unwrap();
assert!(cache.config().is_enabled(Resource::Member));
assert!(!cache.config().is_enabled(Resource::Presence));Sourcepub fn cache_backend<C: Backend>(self, backend: C) -> ClientBuilder<C>
pub fn cache_backend<C: Backend>(self, backend: C) -> ClientBuilder<C>
Keeps the cache in stores created by backend instead of the default
DashMapBackend (D-172), and enables the cache: with
CacheConfig::default unless cache is called too (in any order).
discord.js counterpart: the makeCache option of ClientOptions.
§Examples
use djs_rs::{Client, cache::DashMapBackend};
// Any `djs_cache::Backend` works; this is the default one, named explicitly.
let client: Client<DashMapBackend> = Client::builder("my-token")
.cache_backend(DashMapBackend::new())
.build();
assert!(client.cache().is_some());Sourcepub fn build(self) -> Client<B>
pub fn build(self) -> Client<B>
Builds the client. It does not connect until Client::login is called.
discord.js counterpart: new Client(options).
Trait Implementations§
Auto Trait Implementations§
impl<B = DashMapBackend> !RefUnwindSafe for ClientBuilder<B>
impl<B = DashMapBackend> !UnwindSafe for ClientBuilder<B>
impl<B> Freeze for ClientBuilder<B>where
B: Freeze,
impl<B> Send for ClientBuilder<B>
impl<B> Sync for ClientBuilder<B>
impl<B> Unpin for ClientBuilder<B>where
B: Unpin,
impl<B> UnsafeUnpin for ClientBuilder<B>where
B: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Classify for T
impl<T> Classify for T
type Classified = T
fn classify(self) -> T
§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more