You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

post-execution.md 1.7 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Preface
  2. When developing a command system or modules, you may want to consider
  3. building a post-execution handling system so you can have a finer
  4. control over commands. Discord.NET offers several different
  5. post-execution workflow for you to work with.
  6. If you recall, in the [Command Guide], we've shown the following
  7. example for executing and handling commands,
  8. [!code[Command Handler](samples/command_handler.cs)]
  9. You may notice that after we perform [ExecuteAsync], we store the
  10. result and print it to the chat. This is essentially the most
  11. basic post-execution handling. With this in mind, we could start doing
  12. things like the following,
  13. [!code[Basic Command Handler](samples/post-execution_basic.cs)]
  14. **But!** This may not always be preferred, because you are
  15. creating your post-execution logic *with* the essential command
  16. handler. This could lead to messy code and has another potential
  17. issue, working with `RunMode.Async`.
  18. If your command is marked with `RunMode.Async`, [ExecuteAsync] will
  19. return a successful [ExecuteResult] instead of whatever results
  20. the actual command may return. Because of the way `RunMode.Async`
  21. [works](../../faq/commands.md), handling within the command handler
  22. may not always achieve the desired effect.
  23. ## CommandExecuted Event
  24. Enter [CommandExecuted], an event that was introduced in
  25. Discord.NET 2.0. This event is raised **when the command is
  26. sucessfully executed** and is not prone to `RunMode.Async`'s
  27. [ExecuteAsync] drawbacks.
  28. [CommandExecuted]: xref:Discord.Commands.CommandService.CommandExecuted
  29. [ExecuteAsync]: xref:Discord.Commands.CommandService.ExecuteAsync*
  30. [ExecuteResult]: xref:Discord.Commands.ExecuteResult
  31. [Command Guide]: Commands.md