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

Builder to customize the operation of a shard.

Implementations§

source§

impl ConfigBuilder

source

pub fn new(token: String, intents: Intents) -> Self

Create a new builder to configure and construct a shard.

Refer to each method to learn their default values.

Panics

Panics if loading TLS certificates fails.

source

pub const fn with_config(config: Config) -> Self

Create a new builder from an existing configuration.

source

pub fn build(self) -> Config

Consume the builder, constructing a shard.

source

pub const fn event_types(self, event_types: EventTypeFlags) -> Self

Set the event types to process.

This is an optimization technique; all events not included in the provided event type flags will not be deserialized by the gateway and will be discarded.

source

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

Set the properties to identify with.

This may be used if you want to set a different operating system, for example.

Examples

Set the identify properties for a shard:

use std::env::{self, consts::OS};
use twilight_gateway::{Config, Intents, Shard};
use twilight_model::gateway::payload::outgoing::identify::IdentifyProperties;

let token = env::var("DISCORD_TOKEN")?;
let properties = IdentifyProperties::new("twilight.rs", "twilight.rs", OS);

let config = Config::builder(token, Intents::empty())
    .identify_properties(properties)
    .build();
source

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

Set the maximum number of members in a guild to load the member list.

Default value is 50. The minimum value is 50 and the maximum is 250.

Examples

If you pass 200, then if there are 250 members in a guild the member list won’t be sent. If there are 150 members, then the list will be sent.

Panics

Panics if the provided value is below 50 or above 250.

source

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

Set the presence to use automatically when starting a new session.

Default is no presence, which defaults to strictly being “online” with no special qualities.

Examples

Set the bot user’s presence to idle with the status “Not accepting commands”:

use std::env;
use twilight_gateway::{Config, Intents, Shard, ShardId};
use twilight_model::gateway::{
    payload::outgoing::update_presence::UpdatePresencePayload,
    presence::{ActivityType, MinimalActivity, Status},
};

let config = Config::builder(env::var("DISCORD_TOKEN")?, Intents::empty())
    .presence(UpdatePresencePayload::new(
        vec![MinimalActivity {
            kind: ActivityType::Playing,
            name: "Not accepting commands".into(),
            url: None,
        }
        .into()],
        false,
        None,
        Status::Idle,
    )?)
    .build();

let shard = Shard::with_config(ShardId::ONE, config);
source

pub fn proxy_url(self, proxy_url: String) -> Self

Set the proxy URL for connecting to the gateway.

Resumes are always done to the URL specified in resume_gateway_url.

source

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

Set the queue to use for queueing shard sessions.

Defaults to a LocalQueue.

Refer to the queue module for more information.

source

pub const fn ratelimit_messages(self, ratelimit_messages: bool) -> Self

Set whether or not outgoing messages will be ratelimited.

Useful when running behind a proxy gateway. Running without a functional ratelimiter will get you ratelimited.

Defaults to being enabled.

source

pub fn session(self, session: Session) -> Self

Set the gateway session to use when connecting to the gateway.

In practice this will result in the shard attempting to send a Resume to the gateway instead of identifying and creating a new session. Refer to the documentation for Session for more information.

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 Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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 Twhere
U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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