streamocracy/commands/
ping.rs1use crate::commands::SlashCommand;
2use crate::config::Config;
3use serenity::all::{
4 CommandInteraction, Context, CreateCommand, CreateInteractionResponse,
5 CreateInteractionResponseMessage,
6};
7use tracing::info;
8
9pub struct PingCommand;
11
12#[serenity::async_trait]
13impl SlashCommand for PingCommand {
14 fn name(&self) -> &'static str {
15 "ping"
16 }
17
18 fn register(&self) -> CreateCommand {
19 CreateCommand::new(self.name()).description("Check if the bot is responsive")
20 }
21
22 async fn run(&self, ctx: Context, command: CommandInteraction, _config: Config) {
23 let user = &command.user;
24 info!("Command 'ping' invoked by {} ({})", user.name, user.id);
25
26 if let Err(e) = command
27 .create_response(
28 &ctx.http,
29 CreateInteractionResponse::Message(
30 CreateInteractionResponseMessage::new().content("Pong! 🏓"),
31 ),
32 )
33 .await
34 {
35 tracing::error!("Failed to respond to ping: {}", e);
36 }
37 }
38}