Get ModalInteraction reply message

Hello, After an UserContextCommand interaction, I reply with a Modal. Once this Modal is Submitted, I send a reply Message in the channel. On this message, I set a ButtonComponent to edit the reason of the sanction. I use for that a createMessageComponentCollector.
The first problem is that I don't have any interactions on the event collect.
The second problem is that I don't have anywehere the message of the ModalSubmitInteraction reply, and I need it to delete the message
My code:
await modalInteraction.reply({
content: client.translate(settings.lang, "MUTE_SUCESSFUL", {
user: member.user,
text: {1: client.translate(settings.lang, "SANCTION_NO_REASON_USER")}
}),
components: [action]
}).then(async m => {
if (!m) m = await interaction.fetchReply()
console.log(m)
const collector = m.createMessageComponentCollector({
filter: i => i.first().customId === "edit_mod_reason_sanct_message",
idle: 30*1000,
componentType: ComponentType.Button,
})
console.log(collector)
collector.on("collect", int => {
console.log("Collected")
if (!int.channel.permissionsFor(int.member).has(PermissionsBitField.Flags.ModerateMembers)) return int.reply({content: client.translate(settings.lang, "MISSING_PERMISSIONS", {text: {1: "ModerateMembers"}}), ephemeral: true})
const editModal = new ModalBuilder()
.setCustomId("edit_mod_reason_sanct_modal")
.setTitle("Edit Reason")
.setComponents([
new ActionRowBuilder().addComponents([
new TextInputBuilder()
.setLabel("Reason")
.setPlaceholder("The reason of the mute")
.setCustomId("reason")
.setStyle(TextInputStyle.Paragraph)
.setRequired(true)
])
])
int.showModal(editModal)
const filter = modal => modal.customId === "edit_mod_reason_sanct_modal"
int.awaitModalSubmit({ filter, time: 60_000}).then(async (modalInteraction) => {
const reason = modalInteraction.components[0].components[0].value
const userInfos = await client.getUser(member)
const sanctionData = userInfos.modlogs.pop()
sanctionData.reason = reason
userInfos.modlogs.push(sanctionData)
await client.updateUser(userInfos, {modlogs: userInfos.modlogs})

const sanctionMessage = await client.channels.cache.get(client.config.modLogChannel).messages.fetch({message: sanctionData.msg})
sanctionMessage.embeds[0].fields.find(f => f.name === "Reason").value = sanctionData.reason
await sanctionMessage.edit({embeds: sanctionMessage.embeds})

return m.edit({content: client.translate(settings.lang, "MUTE_SUCESSFUL", {user: member.user, text: {1: reason}}), components: []})
})
})
collector.on("end", e => {
client.log("error", e)
if (m.deletable) return m.delete().catch(e => client.log("error", e))
})
})
await modalInteraction.reply({
content: client.translate(settings.lang, "MUTE_SUCESSFUL", {
user: member.user,
text: {1: client.translate(settings.lang, "SANCTION_NO_REASON_USER")}
}),
components: [action]
}).then(async m => {
if (!m) m = await interaction.fetchReply()
console.log(m)
const collector = m.createMessageComponentCollector({
filter: i => i.first().customId === "edit_mod_reason_sanct_message",
idle: 30*1000,
componentType: ComponentType.Button,
})
console.log(collector)
collector.on("collect", int => {
console.log("Collected")
if (!int.channel.permissionsFor(int.member).has(PermissionsBitField.Flags.ModerateMembers)) return int.reply({content: client.translate(settings.lang, "MISSING_PERMISSIONS", {text: {1: "ModerateMembers"}}), ephemeral: true})
const editModal = new ModalBuilder()
.setCustomId("edit_mod_reason_sanct_modal")
.setTitle("Edit Reason")
.setComponents([
new ActionRowBuilder().addComponents([
new TextInputBuilder()
.setLabel("Reason")
.setPlaceholder("The reason of the mute")
.setCustomId("reason")
.setStyle(TextInputStyle.Paragraph)
.setRequired(true)
])
])
int.showModal(editModal)
const filter = modal => modal.customId === "edit_mod_reason_sanct_modal"
int.awaitModalSubmit({ filter, time: 60_000}).then(async (modalInteraction) => {
const reason = modalInteraction.components[0].components[0].value
const userInfos = await client.getUser(member)
const sanctionData = userInfos.modlogs.pop()
sanctionData.reason = reason
userInfos.modlogs.push(sanctionData)
await client.updateUser(userInfos, {modlogs: userInfos.modlogs})

const sanctionMessage = await client.channels.cache.get(client.config.modLogChannel).messages.fetch({message: sanctionData.msg})
sanctionMessage.embeds[0].fields.find(f => f.name === "Reason").value = sanctionData.reason
await sanctionMessage.edit({embeds: sanctionMessage.embeds})

return m.edit({content: client.translate(settings.lang, "MUTE_SUCESSFUL", {user: member.user, text: {1: reason}}), components: []})
})
})
collector.on("end", e => {
client.log("error", e)
if (m.deletable) return m.delete().catch(e => client.log("error", e))
})
})
I hope you can help me. Thank you
2 Replies
d.js docs
d.js docs2y ago
• 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.
Merlode
Merlode2y ago
I use the discord.js@14.1.2 And the version 18.7.0 of Node I will try that. Thank you ! That's not the full part of the code. There is a modalInteractionSubmit before but this part works Oh, ok But that's work. Thank you very much !