use super::{Context, Error}; use super::utils::serenity; #[poise::command( slash_command, subcommands("add_channel"), required_permissions = "ADMINISTRATOR" )] pub async fn logging(_ctx: Context<'_>, _arg: String) -> Result<(), Error> { Ok(()) } #[poise::command(slash_command, aliases("add-channel"))] pub async fn add_channel( ctx: Context<'_>, #[description = "New logging channel"] channel: serenity::Channel, ) -> Result<(), Error> { let channel_id = channel.id(); let response = match ctx.guild_id() { None => "Error: Could not determine the guild's ID.".to_owned(), Some(guild_id) => { match ctx .data() .database .set_logging_channel(guild_id, channel_id) .await { Ok(_) => format!( "Added channel <#{channel_id}> as a logging channel" ), Err(e) => { if let Some(db_error) = e.as_database_error() { if db_error.is_unique_violation() { format!("Channel <#{channel_id}> is already a logging channel") } else { format!("Error: {:?}", e) } } else { format!( "Something bad happened with the database: {e:?}" ) } } } } }; ctx.say(response).await?; Ok(()) }