From 7bbb21bff1bd8df2552262f0a27531b7e3c6b220 Mon Sep 17 00:00:00 2001 From: Hsu Still <341464@gmail.com> Date: Sun, 8 Apr 2018 00:44:54 +0800 Subject: [PATCH] Add RuntimeResult demo --- docs/guides/commands/post-execution.md | 4 ++++ .../commands/samples/command_executed_adv_demo.cs | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 docs/guides/commands/samples/command_executed_adv_demo.cs diff --git a/docs/guides/commands/post-execution.md b/docs/guides/commands/post-execution.md index 14701ad8a..77a166746 100644 --- a/docs/guides/commands/post-execution.md +++ b/docs/guides/commands/post-execution.md @@ -93,6 +93,10 @@ Here's an example of a command that utilizes such logic: [!code[Usage](samples/customresult_usage.cs)] +And now we can check for it in our [CommandExecuted] handler: + +[!code[Usage](samples/command_executed_adv_demo.cs)] + ## CommandService.Log Event We have so far covered the handling of various result types, but we diff --git a/docs/guides/commands/samples/command_executed_adv_demo.cs b/docs/guides/commands/samples/command_executed_adv_demo.cs new file mode 100644 index 000000000..1ce40c51d --- /dev/null +++ b/docs/guides/commands/samples/command_executed_adv_demo.cs @@ -0,0 +1,13 @@ +public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext context, IResult result) +{ + switch(result) + { + case MyCustomResult customResult: + // do something extra with it + break; + default: + if (!string.IsNullOrEmpty(result.ErrorReason)) + await context.Channel.SendMessageAsync(result.ErrorReason); + break; + } +} \ No newline at end of file