Struct twilight_gateway::ConfigBuilder
source · pub struct ConfigBuilder { /* private fields */ }
Expand description
Builder to customize the operation of a shard.
Implementations§
source§impl ConfigBuilder
impl ConfigBuilder
sourcepub fn new(token: String, intents: Intents) -> Self
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.
sourcepub const fn with_config(config: Config) -> Self
👎Deprecated since 0.15.3: use From<Config> instead
pub const fn with_config(config: Config) -> Self
Create a new builder from an existing configuration.
sourcepub const fn event_types(self, event_types: EventTypeFlags) -> Self
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.
sourcepub fn identify_properties(
self,
identify_properties: IdentifyProperties
) -> Self
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();
sourcepub const fn large_threshold(self, large_threshold: u64) -> Self
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.
sourcepub fn presence(self, presence: UpdatePresencePayload) -> Self
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::{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);
sourcepub fn proxy_url(self, proxy_url: String) -> Self
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
.
sourcepub fn queue(self, queue: Arc<dyn Queue>) -> Self
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.
sourcepub const fn ratelimit_messages(self, ratelimit_messages: bool) -> Self
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.