Struct serenity::client::ClientBuilder
source · [−]pub struct ClientBuilder { /* private fields */ }
client
and gateway
only.Implementations
sourceimpl 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
or Self::framework_arc
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
or Self::framework_arc
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 get_token(&self) -> Option<&str>
pub fn get_token(&self) -> Option<&str>
Gets the current token used for the Http
client.
This can be unwrapped safely unless used after awaiting the builder.
sourcepub fn application_id(self, application_id: u64) -> Self
pub fn application_id(self, application_id: u64) -> 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) -> Option<&TypeMap>
pub fn get_type_map(&self) -> Option<&TypeMap>
Gets the type map. See Self::type_map
for more info.
This can be unwrapped safely unless used after awaiting the builder.
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<F>(self, f: F) -> Self where
F: FnOnce(&mut CacheSettings) -> &mut CacheSettings,
Available on crate feature cache
only.
pub fn cache_settings<F>(self, f: F) -> Self where
F: FnOnce(&mut CacheSettings) -> &mut CacheSettings,
cache
only.Sets the settings of the cache.
Refer to Settings
for more information.
sourcepub fn get_cache_settings(&self) -> Option<&CacheSettings>
Available on crate feature cache
only.
pub fn get_cache_settings(&self) -> Option<&CacheSettings>
cache
only.Gets the cache settings. See Self::cache_settings
for more info.
This can be unwrapped safely unless used after awaiting the builder.
sourcepub fn framework<F>(self, framework: F) -> Self where
F: Framework + Send + Sync + 'static,
Available on crate feature framework
only.
pub fn framework<F>(self, framework: F) -> Self where
F: Framework + Send + Sync + '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,
use the Self::framework_arc
-method instead.
sourcepub fn framework_arc<T: Framework + Send + Sync + 'static>(
self,
framework: Arc<T>
) -> Self
Available on crate feature framework
only.
pub fn framework_arc<T: Framework + Send + Sync + 'static>(
self,
framework: Arc<T>
) -> Self
framework
only.This method allows to pass an Arc
’ed framework
- this step is
done for you in the Self::framework
-method, if you don’t need the
extra control.
You can provide a clone and keep the original to manually dispatch.
sourcepub fn get_framework(&self) -> Option<Arc<dyn Framework + Send + Sync>>
Available on crate feature framework
only.
pub fn get_framework(&self) -> Option<Arc<dyn Framework + Send + Sync>>
framework
only.Gets the framework, if already initialized. See Self::framework
for more info.
sourcepub fn voice_manager<V>(self, voice_manager: V) -> Self where
V: VoiceGatewayManager + Send + Sync + 'static,
Available on crate feature voice
only.
pub fn voice_manager<V>(self, voice_manager: V) -> Self where
V: VoiceGatewayManager + Send + Sync + '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 + Send + Sync + 'static>
) -> Self
Available on crate feature voice
only.
pub fn voice_manager_arc(
self,
voice_manager: Arc<dyn VoiceGatewayManager + Send + Sync + '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 + Send + Sync>>
Available on crate feature voice
only.
pub fn get_voice_manager(
&self
) -> Option<Arc<dyn VoiceGatewayManager + Send + Sync>>
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
Sets 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
Sets an event handler with multiple methods for each possible event. Passed by Arc.
sourcepub fn get_event_handler(&self) -> Option<Arc<dyn EventHandler>>
pub fn get_event_handler(&self) -> Option<Arc<dyn EventHandler>>
Gets the event handler, if already initialized. 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
Sets an event handler with a single method where all received gateway events will be dispatched.
sourcepub fn get_raw_event_handler(&self) -> Option<Arc<dyn RawEventHandler>>
pub fn get_raw_event_handler(&self) -> Option<Arc<dyn RawEventHandler>>
Gets the raw event handler, if already initialized. See Self::raw_event_handler
for more
info.
Trait Implementations
sourceimpl Future for ClientBuilder
impl Future for ClientBuilder
Auto Trait Implementations
impl !RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl !Sync for ClientBuilder
impl Unpin for ClientBuilder
impl !UnwindSafe for ClientBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> FutureExt for T where
T: Future + ?Sized,
impl<T> FutureExt for T where
T: Future + ?Sized,
fn map<U, F>(self, f: F) -> Map<Self, F> where
F: FnOnce(Self::Output) -> U,
fn map<U, F>(self, f: F) -> Map<Self, F> where
F: FnOnce(Self::Output) -> U,
Map this future’s output to a different type, returning a new future of the resulting type. Read more
fn map_into<U>(self) -> MapInto<Self, U> where
Self::Output: Into<U>,
fn map_into<U>(self) -> MapInto<Self, U> where
Self::Output: Into<U>,
Map this future’s output to a different type, returning a new future of the resulting type. Read more
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> where
F: FnOnce(Self::Output) -> Fut,
Fut: Future,
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> where
F: FnOnce(Self::Output) -> Fut,
Fut: Future,
Chain on a computation for when a future finished, passing the result of
the future to the provided closure f
. Read more
fn left_future<B>(self) -> Either<Self, B> where
B: Future<Output = Self::Output>,
fn left_future<B>(self) -> Either<Self, B> where
B: Future<Output = Self::Output>,
Wrap this future in an Either
future, making it the left-hand variant
of that Either
. Read more
fn right_future<A>(self) -> Either<A, Self> where
A: Future<Output = Self::Output>,
fn right_future<A>(self) -> Either<A, Self> where
A: Future<Output = Self::Output>,
Wrap this future in an Either
future, making it the right-hand variant
of that Either
. Read more
fn into_stream(self) -> IntoStream<Self>
fn into_stream(self) -> IntoStream<Self>
Convert this future into a single element stream. Read more
fn flatten(self) -> Flatten<Self> where
Self::Output: Future,
fn flatten(self) -> Flatten<Self> where
Self::Output: Future,
Flatten the execution of this future when the output of this future is itself another future. Read more
fn flatten_stream(self) -> FlattenStream<Self> where
Self::Output: Stream,
fn flatten_stream(self) -> FlattenStream<Self> where
Self::Output: Stream,
Flatten the execution of this future when the successful result of this future is a stream. Read more
fn fuse(self) -> Fuse<Self>
fn fuse(self) -> Fuse<Self>
Fuse a future such that poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read more
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnOnce(&Self::Output),
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnOnce(&Self::Output),
Do something with the output of a future before passing it on. Read more
fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
std
only.Catches unwinding panics while polling the future. Read more
std
only.Create a cloneable handle to this future where all handles will resolve to the same result. Read more
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)
channel
and std
only.Turn this future into a future that yields ()
on completion and sends
its output to another future on a separate task. Read more
fn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>> where
Self: 'a + Send,
fn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>> where
Self: 'a + Send,
alloc
only.Wrap the future in a Box, pinning it. Read more
fn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>> where
Self: 'a,
fn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>> where
Self: 'a,
alloc
only.Wrap the future in a Box, pinning it. Read more
fn unit_error(self) -> UnitError<Self>
fn unit_error(self) -> UnitError<Self>
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>. Read more
fn never_error(self) -> NeverError<Self>
fn never_error(self) -> NeverError<Self>
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>. Read more
fn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
fn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
A convenience for calling Future::poll
on Unpin
future types.
fn now_or_never(self) -> Option<Self::Output>
fn now_or_never(self) -> Option<Self::Output>
Evaluates and consumes the future, returning the resulting output if
the future is ready after the first call to Future::poll
. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<F> IntoFuture for F where
F: Future,
impl<F> IntoFuture for F where
F: Future,
type Output = <F as Future>::Output
type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type IntoFuture = F
type IntoFuture = F
into_future
)Which kind of future are we turning this into?
sourcefn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
into_future
)Creates a future from a value.
impl<Fut> TryFutureExt for Fut where
Fut: TryFuture + ?Sized,
impl<Fut> TryFutureExt for Fut where
Fut: TryFuture + ?Sized,
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok> where
Self::Ok: Sink<Item>,
<Self::Ok as Sink<Item>>::Error == Self::Error,
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok> where
Self::Ok: Sink<Item>,
<Self::Ok as Sink<Item>>::Error == Self::Error,
sink
only.Flattens the execution of this future when the successful result of this
future is a [Sink
]. Read more
fn map_ok<T, F>(self, f: F) -> MapOk<Self, F> where
F: FnOnce(Self::Ok) -> T,
fn map_ok<T, F>(self, f: F) -> MapOk<Self, F> where
F: FnOnce(Self::Ok) -> T,
Maps this future’s success value to a different value. Read more
fn map_ok_or_else<T, E, F>(self, e: E, f: F) -> MapOkOrElse<Self, F, E> where
F: FnOnce(Self::Ok) -> T,
E: FnOnce(Self::Error) -> T,
fn map_ok_or_else<T, E, F>(self, e: E, f: F) -> MapOkOrElse<Self, F, E> where
F: FnOnce(Self::Ok) -> T,
E: FnOnce(Self::Error) -> T,
Maps this future’s success value to a different value, and permits for error handling resulting in the same type. Read more
fn map_err<E, F>(self, f: F) -> MapErr<Self, F> where
F: FnOnce(Self::Error) -> E,
fn map_err<E, F>(self, f: F) -> MapErr<Self, F> where
F: FnOnce(Self::Error) -> E,
Maps this future’s error value to a different value. Read more
fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F> where
F: FnOnce(Self::Ok) -> Fut,
Fut: TryFuture<Error = Self::Error>,
fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F> where
F: FnOnce(Self::Ok) -> Fut,
Fut: TryFuture<Error = Self::Error>,
Executes another future after this one resolves successfully. The success value is passed to a closure to create this subsequent future. Read more
fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F> where
F: FnOnce(Self::Error) -> Fut,
Fut: TryFuture<Ok = Self::Ok>,
fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F> where
F: FnOnce(Self::Error) -> Fut,
Fut: TryFuture<Ok = Self::Ok>,
Executes another future if this one resolves to an error. The error value is passed to a closure to create this subsequent future. Read more
fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F> where
F: FnOnce(&Self::Ok),
fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F> where
F: FnOnce(&Self::Ok),
Do something with the success value of a future before passing it on. Read more
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F> where
F: FnOnce(&Self::Error),
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F> where
F: FnOnce(&Self::Error),
Do something with the error value of a future before passing it on. Read more
fn try_flatten(self) -> TryFlatten<Self, Self::Ok> where
Self::Ok: TryFuture,
<Self::Ok as TryFuture>::Error == Self::Error,
fn try_flatten(self) -> TryFlatten<Self, Self::Ok> where
Self::Ok: TryFuture,
<Self::Ok as TryFuture>::Error == Self::Error,
Flatten the execution of this future when the successful result of this future is another future. Read more
fn try_flatten_stream(self) -> TryFlattenStream<Self> where
Self::Ok: TryStream,
<Self::Ok as TryStream>::Error == Self::Error,
fn try_flatten_stream(self) -> TryFlattenStream<Self> where
Self::Ok: TryStream,
<Self::Ok as TryStream>::Error == Self::Error,
Flatten the execution of this future when the successful result of this future is a stream. Read more
fn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> where
F: FnOnce(Self::Error) -> Self::Ok,
fn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> where
F: FnOnce(Self::Error) -> Self::Ok,
fn into_future(self) -> IntoFuture<Self>
fn into_future(self) -> IntoFuture<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more