pub struct VoiceManager { /* private fields */ }Expand description
The bot’s voice calls, one per guild: joins voice channels and keeps the calls.
The manager sends Opcode 4 through a VoiceGateway and learns Discord’s answers from
the main gateway’s events, which the bot passes to process (D-324).
djs-rs’s voice feature does both and gives the manager as client.voice(). A cheap-clone
handle: clones share the calls.
discord.js counterpart: joinVoiceChannel and getVoiceConnection of @discordjs/voice;
songbird: Songbird.
§Examples
use djs_voice::{Input, VoiceManager};
let manager = VoiceManager::new(bot, 1, Shards);
// Every event of the main gateway goes through `process`.
let events = manager.clone();
tokio::spawn(async move {
loop {
events.process(&next_event().await);
}
});
let call = manager.join(guild, channel).await?;
call.play(Input::ogg_file("hello.opus").await?);Implementations§
Source§impl VoiceManager
impl VoiceManager
Sourcepub fn new(
bot_user_id: Id<UserMarker>,
shard_count: u32,
gateway: impl VoiceGateway,
) -> VoiceManager
pub fn new( bot_user_id: Id<UserMarker>, shard_count: u32, gateway: impl VoiceGateway, ) -> VoiceManager
A manager of the bot bot_user_id, whose main gateway has shard_count shards (0 is
taken as 1), sending Opcode 4 through gateway.
discord.js counterpart: none (the adapter of each joinVoiceChannel call).
Sourcepub fn process(&self, event: &DispatchEvent)
pub fn process(&self, event: &DispatchEvent)
Takes in an event of the main gateway. Only the bot’s own VOICE_STATE_UPDATEs and
the VOICE_SERVER_UPDATEs of guilds with a call matter; everything else is ignored,
so passing every event is fine.
discord.js counterpart: DiscordGatewayAdapterImplementerMethods#onVoiceStateUpdate
and onVoiceServerUpdate.
Sourcepub async fn join(
&self,
guild_id: Id<GuildMarker>,
channel_id: Id<ChannelMarker>,
) -> Result<Call, JoinError>
pub async fn join( &self, guild_id: Id<GuildMarker>, channel_id: Id<ChannelMarker>, ) -> Result<Call, JoinError>
Joins the voice channel channel_id of guild_id, deafened and not muted
(JoinOptions::default); returns the Call once it is connected (D-322, D-349).
With end-to-end encryption (DAVE, which Discord requires), audio goes out once the bot is in the call’s MLS group: about a second after someone else is in the channel. A bot alone in a channel has no group, so what it plays is not sent (nobody would hear it); nothing is ever sent without end-to-end encryption.
When the bot already has a call in the guild, it moves to the channel, and the same call is returned (D-340).
discord.js counterpart: joinVoiceChannel (which returns at once); songbird:
Songbird::join.
§Errors
JoinError::Gateway when Opcode 4 cannot be sent, JoinError::Timeout when the
call is not ready within 10 seconds (also when the bot lacks the Connect permission:
Discord does not answer), JoinError::Connection when the voice connection fails,
JoinError::Cancelled when the call is left or joined elsewhere meanwhile.
Sourcepub async fn join_with(
&self,
guild_id: Id<GuildMarker>,
channel_id: Id<ChannelMarker>,
options: JoinOptions,
) -> Result<Call, JoinError>
pub async fn join_with( &self, guild_id: Id<GuildMarker>, channel_id: Id<ChannelMarker>, options: JoinOptions, ) -> Result<Call, JoinError>
Trait Implementations§
Source§impl Clone for VoiceManager
impl Clone for VoiceManager
Source§fn clone(&self) -> VoiceManager
fn clone(&self) -> VoiceManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for VoiceManager
impl !UnwindSafe for VoiceManager
impl Freeze for VoiceManager
impl Send for VoiceManager
impl Sync for VoiceManager
impl Unpin for VoiceManager
impl UnsafeUnpin for VoiceManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Classify for T
impl<T> Classify for T
type Classified = T
fn classify(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Declassify for T
impl<T> Declassify for T
type Declassified = T
fn declassify(self) -> T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more