Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ping

Show the time spent waiting for the message to be sent

Usage

/ping

Source code

use crate::discord::{Context, Error};

/// Display the latency of the bot
#[poise::command(slash_command, rename = "ping")]
pub async fn cmd(ctx: Context<'_>) -> Result<(), Error> {
    let text = format!("⌛ Loading...");

    // Discord ping
    let start = std::time::Instant::now();
    let discord_response = ctx.say(text).await?;
    let elapsed = start.elapsed();
    let discord_status = format!("Discord Websocket ⇒ `{}ms`", elapsed.as_millis());

    // Send msg
    let msg = poise::CreateReply::default().content(format!("{}", discord_status));

    discord_response.edit(ctx, msg).await?;

    Ok(())
}