+ This change is to reflect changes made in https://github.com/RogueException/Discord.Net/pull/1164, where CommandInfo is now passed into the CommandExecuted event as an Optional<T>pull/1218/head
@@ -37,11 +37,10 @@ about the impact in the [FAQ](xref:FAQ.Commands.General). | |||||
Enter [CommandExecuted], an event that was introduced in | Enter [CommandExecuted], an event that was introduced in | ||||
Discord.Net 2.0. This event is raised whenever a command is | 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: | Thus, we can begin working on code such as: | ||||
@@ -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) | switch(result) | ||||
{ | { | ||||
@@ -6,7 +6,7 @@ public async Task SetupAsync() | |||||
// Hook the command handler | // Hook the command handler | ||||
_client.MessageReceived += HandleCommandAsync; | _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, | // We have access to the information of the command executed, | ||||
// the context of the command, and the result returned from the | // the context of the command, and the result returned from the | ||||
@@ -20,7 +20,8 @@ public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext co | |||||
// ...or even log the result (the method used should fit into | // ...or even log the result (the method used should fit into | ||||
// your existing log handler) | // 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) | public async Task HandleCommandAsync(SocketMessage msg) | ||||
{ | { | ||||