From a2067ab6742b20b428d4bbca3fdb6e48851a6d53 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 12 Feb 2026 14:06:34 +0100 Subject: [PATCH] feat(commands/utils): adding the ping command --- src/commands/utils/ping.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/commands/utils/ping.rs diff --git a/src/commands/utils/ping.rs b/src/commands/utils/ping.rs new file mode 100644 index 0000000..d324279 --- /dev/null +++ b/src/commands/utils/ping.rs @@ -0,0 +1,32 @@ +use std::time::Instant; + +use serenity::all::{ + CommandInteraction, Context, CreateCommand, CreateInteractionResponse, + CreateInteractionResponseMessage, EditInteractionResponse, +}; + +pub const COMMAND_NAME: &str = "ping"; +pub const COMMAND_DESC: &str = "Show the discord API latency"; + +pub async fn run(ctx: &Context, command: &CommandInteraction) -> Result<(), serenity::Error> { + let message: CreateInteractionResponseMessage = CreateInteractionResponseMessage::new() + .content("🏓 | Pong!") + .ephemeral(true); + + let response: CreateInteractionResponse = CreateInteractionResponse::Message(message); + + let start: Instant = Instant::now(); + command.create_response(&ctx.http, response).await?; + let delta_time: u128 = start.elapsed().as_millis(); + + let edit_msg: String = format!("Ping: **{}**ms", delta_time); + let message: EditInteractionResponse = EditInteractionResponse::new().content(edit_msg); + + command.edit_response(&ctx.http, message).await?; + + Ok(()) +} + +pub fn register() -> CreateCommand { + CreateCommand::new(COMMAND_NAME).description(COMMAND_DESC) +}