feat(commands/utils): adding the ping command
This commit is contained in:
parent
196d26046a
commit
a2067ab674
1 changed files with 32 additions and 0 deletions
32
src/commands/utils/ping.rs
Normal file
32
src/commands/utils/ping.rs
Normal file
|
|
@ -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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue