Initial code upload
This commit is contained in:
25
src/utils.rs
Normal file
25
src/utils.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
// src/utils.rs
|
||||
|
||||
use serenity::{
|
||||
client::Context,
|
||||
model::{
|
||||
id::{GuildId, UserId},
|
||||
voice::VoiceState,
|
||||
},
|
||||
};
|
||||
use tracing::instrument;
|
||||
|
||||
|
||||
// Helper function to find the voice state of a user in a specific guild
|
||||
// using the cached data. Returns None if the user is not in a voice channel
|
||||
// in that guild, or if the guild is not in the cache.
|
||||
#[instrument(skip(ctx))]
|
||||
pub async fn get_voice_state(
|
||||
ctx: &Context,
|
||||
guild_id: GuildId,
|
||||
user_id: UserId
|
||||
) -> Option<VoiceState> {
|
||||
ctx.cache.guild(guild_id).await
|
||||
// Get the guild from cache, then look up the user's voice state in that guild
|
||||
.and_then(|guild| guild.voice_states.get(&user_id).cloned())
|
||||
}
|
||||
Reference in New Issue
Block a user