From 65950e3d50c08d31e3405703fb97a7cc830cd569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Czy=C5=BC?= Date: Tue, 30 Jan 2024 15:22:28 +0100 Subject: [PATCH] mute --- src/commands/music/mute.rs | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/commands/music/mute.rs diff --git a/src/commands/music/mute.rs b/src/commands/music/mute.rs new file mode 100644 index 0000000..f5f261d --- /dev/null +++ b/src/commands/music/mute.rs @@ -0,0 +1,44 @@ +use serenity::framework::standard::macros::command; +use serenity::framework::standard::CommandResult; +use serenity::model::prelude::*; +use serenity::prelude::*; + +use crate::commands::misc::check_msg; + +#[command] +#[only_in(guilds)] +async fn mute(ctx: &Context, msg: &Message) -> CommandResult { + let guild_id = msg.guild_id.unwrap(); + + let manager = songbird::get(ctx) + .await + .expect("Client placed at init") + .clone(); + + let handler_lock = match manager.get(guild_id) { + Some(handler) => handler, + None => { + check_msg(msg.reply(ctx, "Not in a voice channel").await); + + return Ok(()); + } + }; + + let mut handler = handler_lock.lock().await; + + if handler.is_mute() { + check_msg(msg.channel_id.say(&ctx.http, "Already muted").await); + } else { + if let Err(err) = handler.mute(true).await { + check_msg( + msg.channel_id + .say(&ctx.http, format!("Failed: {:?}", err)) + .await, + ); + } + + check_msg(msg.channel_id.say(&ctx.http, "Muted").await); + } + + Ok(()) +}