Struct twilight_gateway::ConfigBuilder

source ·
pub struct ConfigBuilder<Q = InMemoryQueue> { /* 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§

impl<Q> ConfigBuilder<Q>

source

pub fn build(self) -> Config<Q>

Consume the builder, constructing a shard.

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::{ConfigBuilder, 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 = ConfigBuilder::new(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.

The active presence of a session is maintained across re-connections when a session can be successfully resumed, and when a new session has to be made shards will send the configured presence. Manually updating the presence after a disconnection isn’t necessary.

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::{ConfigBuilder, Intents, Shard, ShardId};
use twilight_model::gateway::{
    payload::outgoing::update_presence::UpdatePresencePayload,
    presence::{ActivityType, MinimalActivity, Status},
};

let config = ConfigBuilder::new(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<NewQ>(self, queue: NewQ) -> ConfigBuilder<NewQ>

Set the queue to use for queueing shard sessions.

Defaults to [InMemoryQueue] with its default settings.

Note that [InMemoryQueue] with a max_concurrency of 0 effectively turns itself into a no-op.

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 resume_url(self, resume_url: String) -> Self

Set the resume URL to use when the initial shard connection resumes an old session.

This is only used if the initial shard connection resumes instead of identifying and only affects the first session.

This only has an effect if ConfigBuilder::session is also set.

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<Q: Debug> Debug for ConfigBuilder<Q>

source§

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

Formats the value using the given formatter. Read more
source§

impl<Q> From<Config<Q>> for ConfigBuilder<Q>

source§

fn from(value: Config<Q>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Q> Freeze for ConfigBuilder<Q>
where Q: Freeze,

§

impl<Q = InMemoryQueue> !RefUnwindSafe for ConfigBuilder<Q>

§

impl<Q> Send for ConfigBuilder<Q>
where Q: Send,

§

impl<Q> Sync for ConfigBuilder<Q>
where Q: Sync,

§

impl<Q> Unpin for ConfigBuilder<Q>
where Q: Unpin,

§

impl<Q = InMemoryQueue> !UnwindSafe for ConfigBuilder<Q>

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>,

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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