daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest May 17th, 2018 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [Command("ping")]
  2. [Alias("latency")]
  3. [Summary("Shows the websocket connection's latency and time it takes for me send a message.")]
  4. public async Task PingAsync()
  5. {
  6.     // start a new stopwatch to measure the time it takes for us to send a message
  7.     var sw = Stopwatch.StartNew();
  8.  
  9.     // send the message and store it for later modification
  10.     var msg = await ReplyAsync($"**Websocket latency**: {Context.Client.Latency}ms\n" +
  11.                                "**Response**: ...");
  12.     // pause the stopwatch
  13.     sw.Stop();
  14.  
  15.     // modify the message we sent earlier to display measured time
  16.     await msg.ModifyAsync(x => x.Content = $"**Websocket latency**: {Context.Client.Latency}ms\n" +
  17.                                            $"**Response**: {sw.Elapsed.TotalMilliseconds}ms");
  18. }
RAW Paste Data
Top