Skip to content

Instantly share code, notes, and snippets.

@Quahu
Last active February 12, 2020 01:06
Show Gist options
  • Save Quahu/13367ed9252eab24c69aea693481e5aa to your computer and use it in GitHub Desktop.
Save Quahu/13367ed9252eab24c69aea693481e5aa to your computer and use it in GitHub Desktop.
An example ping command. Assumes your modules are using the SocketCommandContext.
[Command("ping")]
[Alias("latency")]
[Summary("Shows the websocket connection's latency and time it takes for me send a message.")]
public async Task PingAsync()
{
// start a new stopwatch to measure the time it takes for us to send a message
var sw = Stopwatch.StartNew();
// send the message and store it for later modification
var msg = await ReplyAsync($"**Websocket latency**: {Context.Client.Latency}ms\n" +
"**Response**: ...");
// pause the stopwatch
sw.Stop();
// modify the message we sent earlier to display measured time
await msg.ModifyAsync(x => x.Content = $"**Websocket latency**: {Context.Client.Latency}ms\n" +
$"**Response**: {sw.Elapsed.TotalMilliseconds}ms");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment