Command responder - S3nS3IW00/JCommands GitHub Wiki
A class that takes out the necessary methods from Javacord's implementation to be able to send a response to the command. An instance of this can be found in every event.
Responding
There are three types of responses:
- immediately response
- late response
- modal response
Immediately response
This can be used when the response does not take more than 3 seconds
. So basically for responding to errors this could be a good choice.
Responding immediately:
event.getResponder().respondNow()
.setContent("This is a response")
.respond();
Reponse can be sent only for the user by setting the
MessageFlag.EPHEMERAL
flag on the response withInteractionImmediateResponseBuilder#setFlags(MessageFlag...)
Late response
This must be used when the response takes more then 3 seconds
. It is a good practice to use this when the response depends on a proccess. In this case the - actual - response has to be sent within 15 minutes
, otherwise response to the command cannot be sent.
To be able to respond lately, it has to be indicated within 3 seconds
that this response takes more time to proceed. After the process a follow-up message has to be sent that will be the actual response. This can be done by the following way:
event.getResponder().respondLater().thenAccept(updater -> {
updater.setContent("The response takes more time to proceed.").update();
// do the process that does not take more time than 15 minutes
event.getResponder().followUp()
.setContent("This is the actual response.")
.send();
});
Late response also can be sent for only the user with
CommandResponder#respondLaterEphemeral()
method.
Modal response
A modal can be opened in a response to the command usage. Since this resource does not have any specific about modals, more info can be found here.
For example:
event.getResponder().respondWithModal("modalId","Modal Title",
ActionRow.of(TextInput.create(TextInputStyle.SHORT, "text_input_id", "This is a Text Input Field")));