[][src]Struct twilight_gateway::shard::ShardBuilder

pub struct ShardBuilder(_);

Builder to configure and construct a shard.

Use ShardBuilder::new to start configuring a new Shard.

Examples

Create a new shard, setting the large_threshold to 100 and the shard ID to 5 out of 10:

use std::env;
use twilight_gateway::{Intents, Shard};

let token = env::var("DISCORD_TOKEN")?;

let shard = Shard::builder(token, Intents::GUILD_MESSAGE_REACTIONS)
    .large_threshold(100)?
    .shard(5, 10)?
    .build();

Implementations

impl ShardBuilder[src]

pub fn new(token: impl Into<String>, intents: Intents) -> Self[src]

Create a new builder to configure and construct a shard.

Refer to each method to learn their default values.

pub fn build(self) -> Shard[src]

Consume the builder, constructing a shard.

pub fn gateway_url(self, gateway_url: Option<String>) -> Self[src]

Set the URL used for connecting to Discord's gateway

pub fn http_client(self, http_client: HttpClient) -> Self[src]

Set the HTTP client to be used by the shard for getting gateway information.

Default is a new, unconfigured instance of an HTTP client.

pub fn large_threshold(
    self,
    large_threshold: u64
) -> Result<Self, LargeThresholdError>
[src]

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

Default value is 250. 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.

Errors

Returns LargeThresholdError::TooFew if the provided value is below 50.

Returns LargeThresholdError::TooMany if the provided value is above 250.

pub fn presence(self, presence: UpdateStatusInfo) -> Self[src]

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.

pub fn queue(self, queue: Arc<Box<dyn Queue>>) -> Self[src]

Set the queue to use for queueing shard connections.

You probably don't need to set this yourself, because the Cluster manages that for you. Refer to the queue module for more information.

The default value is a queue used only by this shard, or a queue used by all shards when ran by a Cluster.

pub fn shard(
    self,
    shard_id: u64,
    shard_total: u64
) -> Result<Self, ShardIdError>
[src]

Set the shard ID to connect as, and the total number of shards used by the bot.

The shard ID is 0-indexed, while the total is 1-indexed.

The default value is a shard ID of 0 and a shard total of 1, which is good for smaller bots.

Note: If your bot is in over 250'000 guilds then shard_total should probably be a multiple of 16 if you're in the "Large Bot Sharding" program.

Examples

If you have 19 shards, then your last shard will have an ID of 18 out of a total of 19 shards:

use twilight_gateway::{Intents, Shard};
use std::env;

let token = env::var("DISCORD_TOKEN")?;

let shard = Shard::builder(token, Intents::empty()).shard(18, 19)?.build();

Errors

Returns ShardIdError::IdTooLarge if the shard ID to connect as is larger than the total.

Trait Implementations

impl Clone for ShardBuilder[src]

impl Debug for ShardBuilder[src]

impl<T: Into<String>> From<(T, Intents)> for ShardBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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