How to make a button open the modal after clicking it again?

I have a button that lets the user enter feedback. But if the user closes the modal midway, this button will become unavailable. How to make this button respond to multiple clicks to open the modal? My code here:
const feedbackButton = new ButtonBuilder()
.setCustomId("Feedback")
.setLabel("Give Feedback")
.setStyle(ButtonStyle.Primary);
message = await confirmation.update({
embeds: [embed],
components: [
new ActionRowBuilder().addComponents(feedbackButton),
],
});

try {
// Wait for feedback
confirmation = await message.awaitMessageComponent({
filter: collectorFilter,
time: 600_000,
});

const modal = new ModalBuilder()
.setCustomId("feedback")
.setTitle("Give some Feedback!");

// add some input components

try {
await confirmation.showModal(modal);
confirmation = await confirmation.awaitModalSubmit({
time: 300_000,
});
const feedback =
confirmation.fields.getTextInputValue("fbInput");

embed.description =
embed.description + `\nFeedback: ${feedback}`;

return confirmation.update({
embeds: [embed],
components: [],
});
} catch (e) {
// timeout, remove button
return confirmation.editReply({
components: [],
});
}
} catch (e) {
// timeout, remove button
return message.edit({
components: [],
});
}
const feedbackButton = new ButtonBuilder()
.setCustomId("Feedback")
.setLabel("Give Feedback")
.setStyle(ButtonStyle.Primary);
message = await confirmation.update({
embeds: [embed],
components: [
new ActionRowBuilder().addComponents(feedbackButton),
],
});

try {
// Wait for feedback
confirmation = await message.awaitMessageComponent({
filter: collectorFilter,
time: 600_000,
});

const modal = new ModalBuilder()
.setCustomId("feedback")
.setTitle("Give some Feedback!");

// add some input components

try {
await confirmation.showModal(modal);
confirmation = await confirmation.awaitModalSubmit({
time: 300_000,
});
const feedback =
confirmation.fields.getTextInputValue("fbInput");

embed.description =
embed.description + `\nFeedback: ${feedback}`;

return confirmation.update({
embeds: [embed],
components: [],
});
} catch (e) {
// timeout, remove button
return confirmation.editReply({
components: [],
});
}
} catch (e) {
// timeout, remove button
return message.edit({
components: [],
});
}
3 Replies
d.js toolkit
d.js toolkit14mo 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
Syjalo14mo ago
Use the interactionCreate event instead of the Collector.
PurifiedWater
PurifiedWaterOP14mo ago
I see! Thank you very much.
Want results from more Discord servers?
Add your server