interactions.rst 10 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ============
  2. Interactions
  3. ============
  4. Interactions are utilized in message components and slash commands.
  5. Attributes
  6. ==========
  7. +----------------+----------------------+------------------------------------------------------+
  8. | name | type | description |
  9. +================+======================+======================================================+
  10. | id | string | id of the interaction. |
  11. +----------------+----------------------+------------------------------------------------------+
  12. | application_id | string | id of the application associated to the interaction. |
  13. +----------------+----------------------+------------------------------------------------------+
  14. | int | type | type of interaction. |
  15. +----------------+----------------------+------------------------------------------------------+
  16. | data | ``?InteractionData`` | data associated with the interaction. |
  17. +----------------+----------------------+------------------------------------------------------+
  18. | guild | ``?Guild`` | guild interaction was triggered from, null if DM. |
  19. +----------------+----------------------+------------------------------------------------------+
  20. | channel | ``?Channel`` | channel interaction was triggered from. |
  21. +----------------+----------------------+------------------------------------------------------+
  22. | member | ``?Member`` | member that triggered interaction. |
  23. +----------------+----------------------+------------------------------------------------------+
  24. | user | ``User`` | user that triggered interaction. |
  25. +----------------+----------------------+------------------------------------------------------+
  26. | token | string | internal token for responding to interaction. |
  27. +----------------+----------------------+------------------------------------------------------+
  28. | version | int | version of interaction. |
  29. +----------------+----------------------+------------------------------------------------------+
  30. | message | ``?Message`` | message that triggered interaction. |
  31. +----------------+----------------------+------------------------------------------------------+
  32. | locale | ?string | The selected language of the invoking user. |
  33. +----------------+----------------------+------------------------------------------------------+
  34. | guild_locale | ?string | The guild’s preferred locale, if invoked in a guild. |
  35. +----------------+----------------------+------------------------------------------------------+
  36. The locale list can be seen on `Discord API reference <https://discord.com/developers/docs/reference#locales>`_.
  37. Functions on interaction create
  38. ===============================
  39. The following functions are used to respond an interaction after being created ``Event::INTERACTION_CREATE``, responding interaction with wrong type throws a ``LogicException``
  40. +----------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+------------------------------------------------------------------+
  41. | name | description | valid for interaction type |
  42. +==============================================================================================+=============================================================================+==================================================================+
  43. | ``acknowledgeWithResponse(?bool $ephemeral)`` | acknowledges the interaction, creating a placeholder response to be updated | ``APPLICATION_COMMAND``, ``MESSAGE_COMPONENT``, ``MODAL_SUBMIT`` |
  44. +----------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+------------------------------------------------------------------+
  45. | ``acknowledge()`` | defer the interaction | ``MESSAGE_COMPONENT``, ``MODAL_SUBMIT`` |
  46. +----------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+------------------------------------------------------------------+
  47. | ``respondWithMessage(MessageBuilder $builder, ?bool $ephemeral)`` | responds to the interaction with a message. ephemeral is default false | ``APPLICATION_COMMAND``, ``MESSAGE_COMPONENT``, ``MODAL_SUBMIT`` |
  48. +----------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+------------------------------------------------------------------+
  49. | ``autoCompleteResult(array $choices)`` | responds a suggestion to options with auto complete | ``APPLICATION_COMMAND_AUTOCOMPLETE`` |
  50. +----------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+------------------------------------------------------------------+
  51. | ``showModal(string $title, string $custom_id, array $components, ?callable $submit = null)`` | responds to the interaction with a popup modal | ``MODAL_SUBMIT`` |
  52. +----------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------+------------------------------------------------------------------+
  53. Functions after interaction response
  54. ====================================
  55. The following functions can be only used after interaction respond above, otherwise throws a ``RuntimeException`` “Interaction has not been responded to.”
  56. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  57. | name | description | return |
  58. +========================================================================+================================================================================================+======================+
  59. | ``updateMessage(MessageBuilder $message)`` | updates the message the interaction was triggered from. only for message component interaction | ``Promise<void>`` |
  60. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  61. | ``getOriginalResponse()`` | gets the original interaction response | ``Promise<Message>`` |
  62. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  63. | ``updateOriginalResponse(MessageBuilder $message)`` | updates the original interaction response | ``Promise<Message>`` |
  64. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  65. | ``deleteOriginalResponse()`` | deletes the original interaction response | ``Promise<void>`` |
  66. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  67. | ``sendFollowUpMessage(MessageBuilder $builder, ?bool $ephemeral)`` | sends a follow up message to the interaction. ephemeral is defalt false | ``Promise<Message>`` |
  68. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  69. | ``getFollowUpMessage(string $message_id)`` | gets a non ephemeral follow up message from the interaction | ``Promise<Message>`` |
  70. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  71. | ``updateFollowUpMessage(string $message_id, MessageBuilder $builder)`` | updates the follow up message of the interaction | ``Promise<Message>`` |
  72. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+
  73. | ``deleteFollowUpMessage(string $message_id)`` | deletes a follow up message from the interaction | ``Promise<void>`` |
  74. +------------------------------------------------------------------------+------------------------------------------------------------------------------------------------+----------------------+