Last active
February 12, 2020 01:06
-
-
Save Quahu/13367ed9252eab24c69aea693481e5aa to your computer and use it in GitHub Desktop.
An example ping command. Assumes your modules are using the SocketCommandContext.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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