pub struct ClientBuilder { /* private fields */ }
client
and gateway
only.Expand description
A builder implementing IntoFuture
building a Client
to interact with Discord.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new(token: impl AsRef<str>, intents: GatewayIntents) -> Self
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.
Sourcepub fn new_with_http(http: Http, intents: GatewayIntents) -> Self
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.
Sourcepub fn token(self, token: impl AsRef<str>) -> Self
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.
Sourcepub fn application_id(self, application_id: ApplicationId) -> Self
pub fn application_id(self, application_id: ApplicationId) -> Self
Sets the application id.
Sourcepub fn get_application_id(&self) -> Option<ApplicationId>
pub fn get_application_id(&self) -> Option<ApplicationId>
Gets the application ID, if already initialized. See Self::application_id
for more
info.
Sourcepub fn type_map(self, type_map: TypeMap) -> Self
pub fn type_map(self, type_map: TypeMap) -> Self
Sets the entire TypeMap
that will be available in Context
s. A TypeMap
must not
be constructed manually: Self::type_map_insert
can be used to insert one type at a
time.
Sourcepub fn get_type_map(&self) -> &TypeMap
pub fn get_type_map(&self) -> &TypeMap
Gets the type map. See Self::type_map
for more info.
Sourcepub fn type_map_insert<T: TypeMapKey>(self, value: T::Value) -> Self
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 value
s.
Sourcepub fn cache_settings(self, settings: CacheSettings) -> Self
Available on crate feature cache
only.
pub fn cache_settings(self, settings: CacheSettings) -> Self
cache
only.Sets the settings of the cache. Refer to Settings
for more information.
Sourcepub fn get_cache_settings(&self) -> &CacheSettings
Available on crate feature cache
only.
pub fn get_cache_settings(&self) -> &CacheSettings
cache
only.Gets the cache settings. See Self::cache_settings
for more info.
Sourcepub fn framework<F>(self, framework: F) -> Selfwhere
F: Framework + 'static,
Available on crate feature framework
only.
pub fn framework<F>(self, framework: F) -> Selfwhere
F: Framework + 'static,
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
.
Sourcepub fn get_framework(&self) -> Option<&dyn Framework>
Available on crate feature framework
only.
pub fn get_framework(&self) -> Option<&dyn Framework>
framework
only.Gets the framework, if already initialized. See Self::framework
for more info.
Sourcepub fn voice_manager<V>(self, voice_manager: V) -> Selfwhere
V: VoiceGatewayManager + 'static,
Available on crate feature voice
only.
pub fn voice_manager<V>(self, voice_manager: V) -> Selfwhere
V: VoiceGatewayManager + 'static,
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.
Sourcepub fn voice_manager_arc(
self,
voice_manager: Arc<dyn VoiceGatewayManager + 'static>,
) -> Self
Available on crate feature voice
only.
pub fn voice_manager_arc( self, voice_manager: Arc<dyn VoiceGatewayManager + 'static>, ) -> Self
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.
Sourcepub fn get_voice_manager(&self) -> Option<Arc<dyn VoiceGatewayManager>>
Available on crate feature voice
only.
pub fn get_voice_manager(&self) -> Option<Arc<dyn VoiceGatewayManager>>
voice
only.Gets the voice manager, if already initialized. See Self::voice_manager
for more info.
Sourcepub fn intents(self, intents: GatewayIntents) -> Self
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.
Sourcepub fn get_intents(&self) -> GatewayIntents
pub fn get_intents(&self) -> GatewayIntents
Gets the intents. See Self::intents
for more info.
Sourcepub fn event_handler<H: EventHandler + 'static>(self, event_handler: H) -> Self
pub fn event_handler<H: EventHandler + 'static>(self, event_handler: H) -> Self
Adds an event handler with multiple methods for each possible event.
Sourcepub fn event_handler_arc<H: EventHandler + 'static>(
self,
event_handler_arc: Arc<H>,
) -> Self
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.
Sourcepub fn get_event_handlers(&self) -> &[Arc<dyn EventHandler>]
pub fn get_event_handlers(&self) -> &[Arc<dyn EventHandler>]
Gets the added event handlers. See Self::event_handler
for more info.
Sourcepub fn raw_event_handler<H: RawEventHandler + 'static>(
self,
raw_event_handler: H,
) -> Self
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.
Sourcepub fn get_raw_event_handlers(&self) -> &[Arc<dyn RawEventHandler>]
pub fn get_raw_event_handlers(&self) -> &[Arc<dyn RawEventHandler>]
Gets the added raw event handlers. See Self::raw_event_handler
for more info.
Sourcepub fn activity(self, activity: ActivityData) -> Self
pub fn activity(self, activity: ActivityData) -> Self
Sets the initial activity.
Sourcepub fn status(self, status: OnlineStatus) -> Self
pub fn status(self, status: OnlineStatus) -> Self
Sets the initial status.
Sourcepub fn get_presence(&self) -> &PresenceData
pub fn get_presence(&self) -> &PresenceData
Gets the initial presence. See Self::activity
and Self::status
for more info.