Struct songbird::Songbird

source ·
pub struct Songbird { /* private fields */ }
Available on crate feature gateway only.
Expand description

A shard-aware struct responsible for managing Calls.

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

source

pub fn serenity() -> Arc<Self>

Available on crate feature serenity only.

Create a new Songbird instance for serenity.

This must be registered after creation.

source

pub fn serenity_from_config(config: Config) -> Arc<Self>

Available on crate feature serenity only.

Create a new Songbird instance for serenity, using the given configuration.

This must be registered after creation.

source

pub fn twilight<U>(cluster: Arc<TwilightMap>, user_id: U) -> Self
where U: Into<UserId>,

Available on crate feature 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.

source

pub fn twilight_from_config<U>( sender_map: Arc<TwilightMap>, user_id: U, config: Config, ) -> Self
where U: Into<UserId>,

Available on crate feature 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.

source

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.

source

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.

source

pub fn get_or_insert<G>(&self, guild_id: G) -> Arc<Mutex<Call>>
where G: Into<GuildId>,

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.

source

pub fn iter(&self) -> Iter<'_>

Creates an iterator for all Calls currently managed.

source

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.

source

pub async fn join<C, G>( &self, guild_id: G, channel_id: C, ) -> JoinResult<Arc<Mutex<Call>>>
where C: Into<ChannelId>, G: Into<GuildId>,

Available on crate feature 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.

source

pub async fn join_gateway<C, G>( &self, guild_id: G, channel_id: C, ) -> JoinResult<(ConnectionInfo, Arc<Mutex<Call>>)>
where C: Into<ChannelId>, G: Into<GuildId>,

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.

source

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.

source

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

source

pub async fn process(&self, event: &TwilightEvent)

Available on crate feature 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 VoiceStateUpdates and VoiceServerUpdates.

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 Debug for Songbird

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> IntoIterator for &'a Songbird

§

type Item = <Iter<'a> as Iterator>::Item

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl VoiceGatewayManager for Songbird

Available on crate feature serenity only.
source§

fn initialise<'life0, 'async_trait>( &'life0 self, shard_count: u32, user_id: SerenityUser, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Performs initial setup at the start of a connection to Discord. Read more
source§

fn register_shard<'life0, 'async_trait>( &'life0 self, shard_id: u32, sender: Sender<ShardRunnerMessage>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handler fired in response to a Ready event. Read more
source§

fn deregister_shard<'life0, 'async_trait>( &'life0 self, shard_id: u32, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handler fired in response to a disconnect, reconnection, or rebalance. Read more
source§

fn server_update<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, guild_id: SerenityGuild, endpoint: &'life1 Option<String>, token: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Handler for VOICE_SERVER_UPDATE messages. Read more
source§

fn state_update<'life0, 'life1, 'async_trait>( &'life0 self, guild_id: SerenityGuild, voice_state: &'life1 VoiceState, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Handler for VOICE_STATE_UPDATE messages. 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<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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> DebuggableStorage for T
where T: Any + Send + Sync + Debug,