Merlode
DIAdiscord.js - Imagine an app
•Created by Merlode on 2/20/2024 in #djs-questions
Image shows on edit
9 replies
DIAdiscord.js - Imagine an app
•Created by Merlode on 8/8/2022 in #djs-questions
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
I hope you can help me.
Thank you
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 messageMy 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))
})
})
7 replies