Skip to content

Commit

Permalink
Update post-execution article and samples
Browse files Browse the repository at this point in the history
+ This change is to reflect changes made in discord-net#1164, where CommandInfo is now passed into the CommandExecuted event as an Optional<T>
  • Loading branch information
Still Hsu committed Nov 6, 2018
1 parent 15bd644 commit cb7dfc3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions docs/guides/commands/post-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ about the impact in the [FAQ](xref:FAQ.Commands.General).

Enter [CommandExecuted], an event that was introduced in
Discord.Net 2.0. This event is raised whenever a command is
successfully executed **without any run-time exceptions** or **any
parsing or precondition failure**. This means this event can be
used to streamline your post-execution design, and the best thing
about this event is that it is not prone to `RunMode.Async`'s
[ExecuteAsync] drawbacks.
executed, regardless of its execution status. This means this
event can be used to streamline your post-execution design, and the
best thing about this event is that it is not prone
to `RunMode.Async`'s [ExecuteAsync] drawbacks.

Thus, we can begin working on code such as:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext context, IResult result)
public async Task OnCommandExecutedAsync(Optional<CommandInfo> command, ICommandContext context, IResult result)
{
switch(result)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public async Task SetupAsync()
// Hook the command handler
_client.MessageReceived += HandleCommandAsync;
}
public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext context, IResult result)
public async Task OnCommandExecutedAsync(Optional<CommandInfo> command, ICommandContext context, IResult result)
{
// We have access to the information of the command executed,
// the context of the command, and the result returned from the
Expand All @@ -20,7 +20,8 @@ public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext co

// ...or even log the result (the method used should fit into
// your existing log handler)
await _log.LogAsync(new LogMessage(LogSeverity.Info, "CommandExecution", $"{command?.Name} was executed at {DateTime.UtcNow}."));
var commandName = command.HasValue ? command.Name : "A command";
await _log.LogAsync(new LogMessage(LogSeverity.Info, "CommandExecution", $"{commandName} was executed at {DateTime.UtcNow}."));
}
public async Task HandleCommandAsync(SocketMessage msg)
{
Expand Down

0 comments on commit cb7dfc3

Please sign in to comment.