pub struct Songbird { /* private fields */ }
gateway
only.Expand description
A shard-aware struct responsible for managing Call
s.
This manager transparently maps guild state and a source of shard information into individual calls, and forwards state updates which affect call state.
Implementations§
source§impl Songbird
impl Songbird
sourcepub fn serenity() -> Arc<Self>
Available on crate feature serenity
only.
pub fn serenity() -> Arc<Self>
serenity
only.Create a new Songbird instance for serenity.
This must be registered after creation.
sourcepub fn serenity_from_config(config: Config) -> Arc<Self>
Available on crate feature serenity
only.
pub fn serenity_from_config(config: Config) -> Arc<Self>
serenity
only.Create a new Songbird instance for serenity, using the given configuration.
This must be registered after creation.
sourcepub fn twilight<U>(cluster: Arc<TwilightMap>, user_id: U) -> Self
Available on crate feature twilight
only.
pub fn twilight<U>(cluster: Arc<TwilightMap>, user_id: U) -> Self
twilight
only.Create a new Songbird instance for twilight.
Twilight handlers do not need to be registered, but
users are responsible for passing in any events using
process
.
sourcepub fn twilight_from_config<U>(
sender_map: Arc<TwilightMap>,
user_id: U,
config: Config,
) -> Self
Available on crate feature twilight
only.
pub fn twilight_from_config<U>( sender_map: Arc<TwilightMap>, user_id: U, config: Config, ) -> Self
twilight
only.Create a new Songbird instance for twilight.
Twilight handlers do not need to be registered, but
users are responsible for passing in any events using
process
.
sourcepub fn initialise_client_data<U: Into<UserId>>(
&self,
shard_count: u64,
user_id: U,
)
pub fn initialise_client_data<U: Into<UserId>>( &self, shard_count: u64, user_id: U, )
Set the bot’s user, and the number of shards in use.
If this struct is already initialised (e.g., from ::twilight
),
or a previous call, then this function is a no-op.
sourcepub fn get<G: Into<GuildId>>(&self, guild_id: G) -> Option<Arc<Mutex<Call>>>
pub fn get<G: Into<GuildId>>(&self, guild_id: G) -> Option<Arc<Mutex<Call>>>
Retrieves a Call
for the given guild, if one already exists.
sourcepub fn get_or_insert<G>(&self, guild_id: G) -> Arc<Mutex<Call>>
pub fn get_or_insert<G>(&self, guild_id: G) -> Arc<Mutex<Call>>
Retrieves a Call
for the given guild, creating a new one if
none is found.
This will not join any calls, or cause connection state to change.
sourcepub fn set_config(&self, new_config: Config)
pub fn set_config(&self, new_config: Config)
Sets a shared configuration for all drivers created from this manager.
Changes made here will apply to new Call and Driver instances only.
Requires the "driver"
feature.
sourcepub async fn join<C, G>(
&self,
guild_id: G,
channel_id: C,
) -> JoinResult<Arc<Mutex<Call>>>
Available on crate feature driver
only.
pub async fn join<C, G>( &self, guild_id: G, channel_id: C, ) -> JoinResult<Arc<Mutex<Call>>>
driver
only.Connects to a target by retrieving its relevant Call
and
connecting, or creating the handler if required.
This can also switch to the given channel, if a handler already exists for the target and the current connected channel is not equal to the given channel.
The provided channel ID is used as a connection target. The channel must be in the provided guild. This is not checked by the library, and will result in an error. If there is already a connected handler for the guild, and the provided channel is different from the channel that the connection is already connected to, then the handler will switch the connection to the provided channel.
If you only need to retrieve the handler for a target, then use
get
.
Twilight users should read the caveats mentioned in process
.
NOTE: an Err(..)
value will still create a Call
accessible via get
.
sourcepub async fn join_gateway<C, G>(
&self,
guild_id: G,
channel_id: C,
) -> JoinResult<(ConnectionInfo, Arc<Mutex<Call>>)>
pub async fn join_gateway<C, G>( &self, guild_id: G, channel_id: C, ) -> JoinResult<(ConnectionInfo, Arc<Mutex<Call>>)>
Partially connects to a target by retrieving its relevant Call
and
connecting, or creating the handler if required.
This method returns the handle and the connection info needed for other libraries or drivers, such as lavalink, and does not actually start or run a voice call.
NOTE: an Err(..)
value will still create a Call
accessible via get
.
sourcepub async fn leave<G: Into<GuildId>>(&self, guild_id: G) -> JoinResult<()>
pub async fn leave<G: Into<GuildId>>(&self, guild_id: G) -> JoinResult<()>
Retrieves the handler for the given target and leaves the associated voice channel, if connected.
This will not drop the handler, and will preserve it and its settings.
If you do not need to reuse event handlers, configuration, or active tracks
in the underlying driver consider calling remove
to release tasks,
threads, and memory.
This is a wrapper around getting a handler and calling
leave
on it.
sourcepub async fn remove<G: Into<GuildId>>(&self, guild_id: G) -> JoinResult<()>
pub async fn remove<G: Into<GuildId>>(&self, guild_id: G) -> JoinResult<()>
Retrieves the Call
for the given target and leaves the associated
voice channel, if connected.
The handler is then dropped, removing settings for the target.
An Err(…) value implies that the gateway could not be contacted, and that leaving should be attempted again later (i.e., after reconnect).
source§impl Songbird
impl Songbird
sourcepub async fn process(&self, event: &TwilightEvent)
Available on crate feature twilight
only.
pub async fn process(&self, event: &TwilightEvent)
twilight
only.Handle events received on the cluster.
When using twilight, you are required to call this with all inbound
(voice) events, i.e., at least VoiceStateUpdate
s and VoiceServerUpdate
s.
Users must ensure that calls to this function happen on a separate task
to any calls to join
, join_gateway
. The simplest way to ensure this is
to tokio::spawn
any command invocation.
Returned futures generally require the inner Call
to be updated via this function,
and will deadlock if event processing is not carried out on another spawned task.
Trait Implementations§
source§impl<'a> IntoIterator for &'a Songbird
impl<'a> IntoIterator for &'a Songbird
source§impl VoiceGatewayManager for Songbird
Available on crate feature serenity
only.
impl VoiceGatewayManager for Songbird
serenity
only.