1use serenity::all::{
4 Command, CommandInteraction, Context, CreateCommand, CreateInteractionResponse,
5 CreateInteractionResponseMessage, GuildId,
6};
7use tracing::{error, info};
8
9pub struct Utils;
11
12impl Utils {
13 pub async fn ephemeral_response(
15 http: &serenity::all::Http,
16 command: &CommandInteraction,
17 content: impl Into<String>,
18 ) {
19 if let Err(e) = command
20 .create_response(
21 http,
22 CreateInteractionResponse::Message(
23 CreateInteractionResponseMessage::new()
24 .content(content)
25 .ephemeral(true),
26 ),
27 )
28 .await
29 {
30 error!("Failed to send ephemeral response: {}", e);
31 }
32 }
33
34 pub async fn register_commands(
38 ctx: &Context,
39 guild_id: Option<GuildId>,
40 commands: Vec<CreateCommand>,
41 ) {
42 if let Some(guild_id) = guild_id {
43 match guild_id.set_commands(&ctx.http, commands.clone()).await {
44 Ok(cmds) => info!("Registered {} commands in guild {}", cmds.len(), guild_id),
45 Err(e) => error!("Failed to register guild commands: {}", e),
46 }
47 } else {
48 match Command::set_global_commands(&ctx.http, commands).await {
49 Ok(cmds) => info!("Registered {} global commands", cmds.len()),
50 Err(e) => error!("Failed to register global commands: {}", e),
51 }
52 }
53 }
54}