use serenity::all::{CommandDataOptionValue, CommandInteraction, Context}; use serenity::builder::{CreateCommand, CreateCommandOption, CreateEmbed}; use serenity::model::application::CommandOptionType; use crate::util::embed::Embed; use crate::util::user_util::{self, get_vc_id}; pub async fn run(ctx: &Context, command: &CommandInteraction) -> CreateEmbed { let username = command.user.name.as_str(); let options = &command.data.options; let query = command.data.options.first().and_then(|option| { if let CommandDataOptionValue::String(query) = &option.value { Some(query) } else { None } }); if query.is_none() { return Embed::create(username, "Error 400", "There is no query provided"); } let guild_id = match &command.guild_id { Some(guild_id) => guild_id, None => { return Embed::create(username, "GuildId not found", "Could not find guild id."); } }; println!("Guild ID: {:?}", guild_id); let connect_to = get_vc_id(ctx, &guild_id, &command.user.id).expect("Cannot get channel id"); let manager = &songbird::get(ctx) .await .expect("Cannot get Songbird.") .clone(); if !user_util::is_self_connected_to_vc(ctx, &guild_id) { // self is connected to vc, check if user is in same vc let self_channel = user_util::get_self_vc_id(ctx, &guild_id); if self_channel.is_none() { return Embed::create( username, "I am not in a VC.", "Connect me to a VC to start playing music.", ); } let self_channel = self_channel.unwrap(); // Check if user is in the same VC as the bot if self_channel != connect_to { return Embed::create( username, "You are not in my VC.", "Connect to my VC to control the music.", ); } // Connect to VC manager .join(*guild_id, connect_to) .await .expect("Cannot connect>..."); } Embed::create(username, "Searching...", format!("Looking for {:?}", query)) } pub fn register() -> CreateCommand { CreateCommand::new("play") .description("Play music") .add_option( CreateCommandOption::new(CommandOptionType::String, "query", "Link or search term") .required(true), ) }