Different modal IDs still trigger awaitModalSubmit multiple times

I need the user to click the button and enter feedback in the modal. After submission, update the embeds in the original message and another notify message . However, if the user closes the modal midway and then re-clicks the button and submits, awaitModalSubmit will resolve multiple times, resulting in multiple updates. How to avoid this situation?
// Wait for feedback
const collector = await message.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 600_000,
});
collector.on("collect", async (i) => {
logger.debug(i.id);
const modal = new ModalBuilder()
.setCustomId(`feedback-${i.id}`)
.setTitle("Give some Feedback!");
// add input components
await i.showModal(modal);

i.awaitModalSubmit({
time: 600_000,
filter: collectorFilter,
})
.then((modalI) => {
const feedback = modalI.fields.getTextInputValue("fbInput");
embed.description =
embed.description + `\nFeedback: ${feedback}`;
logger.info(embed.description);

// DB process

return modalI.update({
embeds: [embed],
components: [],
});
})
.then(() =>
channelMessage.edit({
embeds: [embed],
}),
)
.catch((e) => {
logger.debug(e.message);
i.editReply({
components: [],
});
});
});
// Wait for feedback
const collector = await message.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 600_000,
});
collector.on("collect", async (i) => {
logger.debug(i.id);
const modal = new ModalBuilder()
.setCustomId(`feedback-${i.id}`)
.setTitle("Give some Feedback!");
// add input components
await i.showModal(modal);

i.awaitModalSubmit({
time: 600_000,
filter: collectorFilter,
})
.then((modalI) => {
const feedback = modalI.fields.getTextInputValue("fbInput");
embed.description =
embed.description + `\nFeedback: ${feedback}`;
logger.info(embed.description);

// DB process

return modalI.update({
embeds: [embed],
components: [],
});
})
.then(() =>
channelMessage.edit({
embeds: [embed],
}),
)
.catch((e) => {
logger.debug(e.message);
i.editReply({
components: [],
});
});
});
Here are the output after open modal three times: [01:58:03.598] DEBUG (27560): 1171388086941405195 [01:58:06.284] DEBUG (27560): 1171388098911948840 [01:58:08.420] DEBUG (27560): 1171388107808055337 [01:58:09.937] INFO (27560): Submission Approved! Status updated from In Review to Complete Feedback: 123 [01:58:09.937] INFO (27560): Submission Approved! Status updated from In Review to Complete Feedback: 123 Feedback: 123 [01:58:09.937] INFO (27560): Submission Approved! Status updated from In Review to Complete Feedback: 123 Feedback: 123 Feedback: 123 [01:58:10.117] DEBUG (27560): Unknown interaction [01:58:10.147] DEBUG (27560): Unknown interaction
No description
No description
7 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Syjalo
Syjalo7mo ago
Have different custom id for each modal or just handle modal submits in the interactionCreate event instead of collectors.
PurifiedWater
PurifiedWater7mo ago
I use ButtonInteraction id as modal id actually (.setCustomId(feedback-${i.id})), it's different every time but awaitModalSubmit still resolve multiple times...
Syjalo
Syjalo7mo ago
It's not. As you said when user clicks the button 2 times it shows 2 models with the same custom id
PurifiedWater
PurifiedWater7mo ago
I add a logger here:
...
await i.showModal(modal);
logger.debug(modal.data.custom_id);
i.awaitModalSubmit({
...
...
await i.showModal(modal);
logger.debug(modal.data.custom_id);
i.awaitModalSubmit({
...
it really gave me different modal ID: [02:12:59.485] DEBUG (36040): feedback-1171391844618358805 [02:13:03.570] DEBUG (36040): feedback-1171391861789818991 [02:13:06.095] DEBUG (36040): feedback-1171391872426582026 Do I need to change other ID?
monbrey
monbrey7mo ago
You could add a check for the matching id in the filter
PurifiedWater
PurifiedWater7mo ago
It works! Thank you!