Skip to main content

ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder { /* private fields */ }
Expand description

Builds a Config. Created by Config::builder.

discord.js counterpart: WebSocketManagerOptions (@discordjs/ws).

Implementations§

Source§

impl ConfigBuilder

Source

pub fn gateway_url(self, url: impl Into<String>) -> Self

Sets the gateway URL for new sessions (default DEFAULT_GATEWAY_URL).

Use the URL returned by Get Gateway Bot. Resumes always use the resume_gateway_url from the READY event instead. ws:// URLs are accepted (useful for tests and proxies).

discord.js counterpart: none (@discordjs/ws uses the URL of Get Gateway Bot).

Source

pub const fn compression(self, compression: Compression) -> Self

Sets the transport compression (default Compression::ZstdStream when the zstd-stream feature is enabled).

discord.js counterpart: the compression option of WebSocketManagerOptions (@discordjs/ws).

Source

pub fn identify_properties(self, properties: IdentifyProperties) -> Self

Sets the connection properties sent when identifying (default: library djs-rs).

discord.js counterpart: the identifyProperties option of WebSocketManagerOptions (@discordjs/ws).

Source

pub const fn large_threshold(self, threshold: u8) -> Self

Sets the member count (50–250) above which Discord stops sending offline members of a guild (Discord’s default is 50).

discord.js counterpart: the largeThreshold option of WebSocketManagerOptions (@discordjs/ws).

Source

pub const fn connect_timeout(self, timeout: Duration) -> Self

Sets how long establishing the WebSocket connection (TCP, TLS and upgrade) may take (default 30 s).

discord.js counterpart: the handshakeTimeout option of WebSocketManagerOptions (@discordjs/ws).

Source

pub const fn hello_timeout(self, timeout: Duration) -> Self

Sets how long to wait for the Hello payload after connecting before reconnecting (default 60 s).

discord.js counterpart: the helloTimeout option of WebSocketManagerOptions (@discordjs/ws).

Source

pub fn presence(self, presence: UpdatePresence) -> Self

Sets the presence (status and activities) sent when identifying (default: none, the bot appears online without an activity).

A shard uses it until MessageSender::update_presence replaces it; that presence is then also kept for later sessions.

discord.js counterpart: the presence client option.

§Examples
use djs_gateway::Config;
use djs_model::gateway::{Activity, Intents, Status, payload::UpdatePresence};

let config = Config::builder("my-token", Intents::GUILDS)
    .presence(UpdatePresence::new(Status::Online, [Activity::watching("you")]))
    .build();
assert!(config.presence().is_some());
Source

pub fn identify_queue(self, queue: Arc<dyn IdentifyQueue>) -> Self

Sets the queue shards wait in before identifying (default: a new LocalIdentifyQueue with max_concurrency 1, shared by clones of the configuration).

Pass a LocalIdentifyQueue created with the bot’s max_concurrency to start several shards at once, or an own IdentifyQueue to coordinate several processes.

discord.js counterpart: the buildIdentifyThrottler option of WebSocketManagerOptions (@discordjs/ws).

§Examples
use std::sync::Arc;

use djs_gateway::{Config, LocalIdentifyQueue};
use djs_model::gateway::Intents;

let config = Config::builder("my-token", Intents::GUILDS)
    .identify_queue(Arc::new(LocalIdentifyQueue::new(16)))
    .build();
assert!(format!("{config:?}").contains("max_concurrency: 16"));
Source

pub fn build(self) -> Config

Builds the configuration.

discord.js counterpart: new WebSocketManager(options) (@discordjs/ws).

Trait Implementations§

Source§

impl Debug for ConfigBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more