#awaitModalSubmit is triggered multiple times

8 messages · Page 1 of 1 (latest)

novel kestrel
#

User click on a button to open a modal, everything is fine if the user just submit. However, if the user close the modal, and open it again later on to submit, now awaitModalSubmit is trigger twice.

this is what I have to get the modal submit

const submitted = await i.awaitModalSubmit({ time: 1000 * 60 * 10 });

if (submitted) {
    await submitted.deferReply();
    // post data to external api
}

This cause two errors, the interaction will already be acknowledges after the first time, and data is posted to external api multiple times (based on how many times user has open and close the modal).

How could I avoid this? Thanks!

little kernel
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

glad mango
#

open modals with unique custom ids

novel kestrel
#

Ah, got it, I will give it a try! Thanks!

novel kestrel
#

Actually, I tried with custom id, it doesn't work. For example, if I give the modal with custom id of modal1, then I would get two ModalSubmitInteraction both with custom id of modal1.

#

Is it intended for awaitModalSubmit to receive multiple ModalSubmitInteraction under this scenarios, or I did something wrong?

gaunt frigate
#

He meant "unique" as each showModal call should be using unique ids

novel kestrel
#

So i should generate a unique custom id, pass it to the modal, and when i get a ModalSubmitInteraction, i then verify if that match my custom id. That would work!