values in modal
I'll send a warning message to the user when they make an error in a component within a modal. However, after sending the warning message, I want the user's old messages to be visible when they reopen the old modal. Is the modal's content deleted when the interaction is replied to? Is there any documentation on this?
When is the values of a modal deleted?
16 Replies
You would need to store the value that the user inputted and if they recreate the modal you set those stored values as the values in the modal interactive components
Yes, I can do this manually, but Discord does this too, and I'm wondering when Discord does this. For example, when the modal interaction doesn't have a response?
You have no control over what Discord does. Once the modal is submitted, Discord clears the cached data
I guess the modal is not deleted when there is no response.
I tried
But it is necessary to close the modal manually.
What do you mean? Close the modal manually?
When you open the modal, type something into it, close the modal screen by pressing the cancel key, and then reopen the same modal, the last text you entered will be displayed.
Yes, that information is cached on the client by Discord. There is no way or it to be controlled by your application
:/
I mean one way to ensure that doesn't happen is to have a different identifier each time
Understood, thanks for the explanation
discord does this only if the modal was not submitted and user closes the modal with some data filled in. So, during an error like let's say the modal interaction was not replied in time, the submit will fail and the user closes the modal. Then discord will save their data as the modal was not submitted.
But if the modal was submitted without an error (the interaction was replied to/deferred on time), discord won't save it.
I hope I'm explaining the right thing π
I don't know if this will work but maybe we could do something like this:
if the submitted values are not valid as per your design, you could reply to the button interaction which showed the modal with
.followUp() saying what's wrong and not reply to the modal's interaction (return; after replying to the button interaction). But since this won't close the modal window, the user might not see what's wrong until they close the modal window themselves (they will probably do because of the submit button not working).
Note: I am assuming you're using a button's interaction to show the modal but this would work with select menu and chat input command interactions as well.There's no need to compromise the user experience by leaving the modal open. I'll save the values ββmanually if necessary.
(I'm showing this modal with a slash command.)
yes that's the best choice, but I was wondering this... will it work with File Upload components too?
I haven't tried it but for me the file upload component is not needed.
I see, then it's fine π