serenity::client

Struct ClientBuilder

Source
pub struct ClientBuilder { /* private fields */ }
Available on crate features client and gateway only.
Expand description

A builder implementing IntoFuture building a Client to interact with Discord.

Implementations§

Source§

impl ClientBuilder

Source

pub fn new(token: impl AsRef<str>, intents: GatewayIntents) -> Self

Construct a new builder to call methods on for the client construction. The token will automatically be prefixed “Bot “ if not already.

Panic: If you have enabled the framework-feature (on by default), you must specify a framework via the Self::framework method, otherwise awaiting the builder will cause a panic.

Source

pub fn new_with_http(http: Http, intents: GatewayIntents) -> Self

Construct a new builder with a Http instance to calls methods on for the client construction.

Panic: If you have enabled the framework-feature (on by default), you must specify a framework via the Self::framework method, otherwise awaiting the builder will cause a panic.

Source

pub fn token(self, token: impl AsRef<str>) -> Self

Sets a token for the bot. If the token is not prefixed “Bot “, this method will automatically do so.

Source

pub fn get_token(&self) -> &str

Gets the current token used for the Http client.

Source

pub fn application_id(self, application_id: ApplicationId) -> Self

Sets the application id.

Source

pub fn get_application_id(&self) -> Option<ApplicationId>

Gets the application ID, if already initialized. See Self::application_id for more info.

Source

pub fn type_map(self, type_map: TypeMap) -> Self

Sets the entire TypeMap that will be available in Contexts. A TypeMap must not be constructed manually: Self::type_map_insert can be used to insert one type at a time.

Source

pub fn get_type_map(&self) -> &TypeMap

Gets the type map. See Self::type_map for more info.

Source

pub fn type_map_insert<T: TypeMapKey>(self, value: T::Value) -> Self

Insert a single value into the internal TypeMap that will be available in Context::data. This method can be called multiple times in order to populate the TypeMap with values.

Source

pub fn cache_settings(self, settings: CacheSettings) -> Self

Available on crate feature cache only.

Sets the settings of the cache. Refer to Settings for more information.

Source

pub fn get_cache_settings(&self) -> &CacheSettings

Available on crate feature cache only.

Gets the cache settings. See Self::cache_settings for more info.

Source

pub fn framework<F>(self, framework: F) -> Self
where F: Framework + 'static,

Available on crate feature framework only.

Sets the command framework to be used. It will receive messages sent over the gateway and then consider - based on its settings - whether to dispatch a command.

Info: If a reference to the framework is required for manual dispatch, you can implement Framework on Arc<YourFrameworkType> instead of YourFrameworkType.

Source

pub fn get_framework(&self) -> Option<&dyn Framework>

Available on crate feature framework only.

Gets the framework, if already initialized. See Self::framework for more info.

Source

pub fn voice_manager<V>(self, voice_manager: V) -> Self
where V: VoiceGatewayManager + 'static,

Available on crate feature voice only.

Sets the voice gateway handler to be used. It will receive voice events sent over the gateway and then consider - based on its settings - whether to dispatch a command.

Info: If a reference to the voice_manager is required for manual dispatch, use the Self::voice_manager_arc-method instead.

Source

pub fn voice_manager_arc( self, voice_manager: Arc<dyn VoiceGatewayManager + 'static>, ) -> Self

Available on crate feature voice only.

This method allows to pass an Arc’ed voice_manager - this step is done for you in the voice_manager-method, if you don’t need the extra control. You can provide a clone and keep the original to manually dispatch.

Source

pub fn get_voice_manager(&self) -> Option<Arc<dyn VoiceGatewayManager>>

Available on crate feature voice only.

Gets the voice manager, if already initialized. See Self::voice_manager for more info.

Source

pub fn intents(self, intents: GatewayIntents) -> Self

Sets all intents directly, replacing already set intents. Intents are a bitflag, you can combine them by performing the |-operator.

§What are Intents

A gateway intent sets the types of gateway events (e.g. member joins, guild integrations, guild emoji updates, …) the bot shall receive. Carefully picking the needed intents greatly helps the bot to scale, as less intents will result in less events to be received hence less processed by the bot.

§Privileged Intents

The intents GatewayIntents::GUILD_PRESENCES, GatewayIntents::GUILD_MEMBERS and GatewayIntents::MESSAGE_CONTENT are privileged. Privileged intents need to be enabled in the developer portal. Once the bot is in 100 guilds or more, the bot must be verified in order to use privileged intents.

Source

pub fn get_intents(&self) -> GatewayIntents

Gets the intents. See Self::intents for more info.

Source

pub fn event_handler<H: EventHandler + 'static>(self, event_handler: H) -> Self

Adds an event handler with multiple methods for each possible event.

Source

pub fn event_handler_arc<H: EventHandler + 'static>( self, event_handler_arc: Arc<H>, ) -> Self

Adds an event handler with multiple methods for each possible event. Passed by Arc.

Source

pub fn get_event_handlers(&self) -> &[Arc<dyn EventHandler>]

Gets the added event handlers. See Self::event_handler for more info.

Source

pub fn raw_event_handler<H: RawEventHandler + 'static>( self, raw_event_handler: H, ) -> Self

Adds an event handler with a single method where all received gateway events will be dispatched.

Source

pub fn get_raw_event_handlers(&self) -> &[Arc<dyn RawEventHandler>]

Gets the added raw event handlers. See Self::raw_event_handler for more info.

Source

pub fn activity(self, activity: ActivityData) -> Self

Sets the initial activity.

Source

pub fn status(self, status: OnlineStatus) -> Self

Sets the initial status.

Source

pub fn get_presence(&self) -> &PresenceData

Gets the initial presence. See Self::activity and Self::status for more info.

Trait Implementations§

Source§

impl IntoFuture for ClientBuilder

Source§

type Output = Result<Client, Error>

The output that the future will produce on completion.
Source§

type IntoFuture = Pin<Box<dyn Future<Output = Result<Client, Error>> + Send>>

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. 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.

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 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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.
Source§

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

Source§

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T