File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use crate :: abstraction:: command:: { CommandContext , CommandResult } ;
2+ use poise:: CreateReply ;
23
34/// Show this menu
45#[ poise:: command(
@@ -26,6 +27,25 @@ Type /help command for more info on a command.",
2627 required_permissions = "SEND_MESSAGES"
2728) ]
2829pub async fn ping ( ctx : CommandContext < ' _ > ) -> CommandResult {
29- ctx. say ( "pong!" ) . await ?;
30+ let handle = ctx. reply ( "Calculating...." ) . await ?;
31+
32+ let handle_message = handle. message ( ) . await ?;
33+
34+ let sent_timestamp = handle_message. timestamp . timestamp_millis ( ) ;
35+ let original_timestamp = ctx. created_at ( ) . timestamp_millis ( ) ;
36+
37+ let rest_latency = sent_timestamp - original_timestamp;
38+ let gateway_latency = ctx. ping ( ) . await . as_millis ( ) ;
39+
40+ handle
41+ . edit (
42+ ctx,
43+ CreateReply :: default ( ) . content ( format ! (
44+ "Pong! Rest latency: {}ms, Gateway latency: {}ms" ,
45+ rest_latency, gateway_latency
46+ ) ) ,
47+ )
48+ . await ?;
49+
3050 Ok ( ( ) )
3151}
You can’t perform that action at this time.
0 commit comments