You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2b-rs/src/commands/music/utils.rs

34 lines
927 B
Rust

use std::sync::Arc;
use serenity::client::Context;
use serenity::model::guild::Guild;
use serenity::model::id::{ChannelId, GuildId, UserId};
use songbird::Call;
use tokio::sync::Mutex;
use crate::utils::error::{BotError, BotResult};
/// Joins a voice channel
pub(crate) async fn join_channel(
ctx: &Context,
channel_id: ChannelId,
guild_id: GuildId,
) -> Arc<Mutex<Call>> {
let manager = songbird::get(ctx)
.await
.expect("Songbird Voice client placed in at initialisation.")
.clone();
let (handler, _) = manager.join(guild_id, channel_id).await;
handler
}
/// Returns the voice channel the author is in
pub(crate) fn get_channel_for_author(author_id: &UserId, guild: &Guild) -> BotResult<ChannelId> {
guild
.voice_states
.get(author_id)
.and_then(|voice_state| voice_state.channel_id)
.ok_or(BotError::from("Not in a voice channel."))
}