Browse Source

Update post-execution article and samples

+ 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
Still Hsu 6 years ago
parent
commit
084643f90f
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
3 changed files with 8 additions and 8 deletions
  1. +4
    -5
      docs/guides/commands/post-execution.md
  2. +1
    -1
      docs/guides/commands/samples/post-execution/command_executed_adv_demo.cs
  3. +3
    -2
      docs/guides/commands/samples/post-execution/command_executed_demo.cs

+ 4
- 5
docs/guides/commands/post-execution.md View File

@@ -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:



+ 1
- 1
docs/guides/commands/samples/post-execution/command_executed_adv_demo.cs View File

@@ -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)
{


+ 3
- 2
docs/guides/commands/samples/post-execution/command_executed_demo.cs View File

@@ -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
@@ -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)
{


Loading…
Cancel
Save