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.

interaction.md 2.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ---
  2. uid: FAQ.Commands.Interactions
  3. title: Interaction service
  4. ---
  5. # Interaction commands in services
  6. A chapter talking about the interaction service framework.
  7. For questions about interactions in general, refer to the [Interactions FAQ]
  8. ## Module dependencies aren't getting populated by Property Injection?
  9. Make sure the properties are publicly accessible and publicly settable.
  10. ## How do I use this * interaction specific method/property?
  11. If your interaction context holds a down-casted version of the interaction object, you need to up-cast it.
  12. Ideally, use pattern matching to make sure its the type of interaction you are expecting it to be.
  13. ## `InteractionService.ExecuteAsync()` always returns a successful result, how do i access the failed command execution results?
  14. If you are using `RunMode.Async` you need to setup your post-execution pipeline around `CommandExecuted` events.
  15. ## How do I check if the executing user has * permission?
  16. Refer to the [documentation about preconditions]
  17. ## How do I send the HTTP Response from inside the command modules.
  18. Set the `RestResponseCallback` property of [InteractionServiceConfig] with a delegate for handling HTTP Responses and use
  19. `RestInteractionModuleBase` to create your command modules. `RespondAsync()` and `DeferAsync()` methods of this module base will use the
  20. `RestResponseCallback` to create interaction responses.
  21. ## Is there a cleaner way of creating parameter choices other than using `[Choice]`?
  22. The default `enum` [TypeConverter] of the Interaction Service will
  23. automatically register `enum`s as multiple choice options.
  24. ## How do I add an optional `enum` parameter but make the default value not visible to the user?
  25. The default `enum` [TypeConverter] of the Interaction Service comes with `[Hide]` attribute that
  26. can be used to prevent certain enum values from getting registered.
  27. ## How does the InteractionService determine the generic TypeConverter to use for a parameter type?
  28. It compares the _target base type_ key of the
  29. [TypeConverter] and chooses the one that sits highest on the inheritance hierarchy.
  30. [TypeConverter]: xref:Discord.Interactions.TypeConverter
  31. [Interactions FAQ]: xref: FAQ.Basics.Interactions
  32. [InteractionServiceConfig]: xref:Discord.Interactions.InteractionServiceConfig
  33. [documentation about preconditions]: xref: Guides.ChatCommands.Preconditions