Turkinator
Turkinator
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Turkinator on 11/12/2023 in #djs-questions
Fetching a slash command reply's ID before it's sent
Title basically explains what I'm trying to do. I'm creating a post system, but instead of constantly doing a chain of replies, I want to just edit the topmost message by passing it's ID throughout all components. postCommand.js
// Deferred Reply
const deferredReply = await interaction.deferReply();

// Send Reply
const reply = await interaction.editReply({
content: "Posting System",
});

// Select Menu
const newSelectMenu = new StringSelectMenuBuilder()
.addOptions(
new SSMOB()
.setLabel("Option1")
.setDescription("The first option.")
.setValue("Option1")
)
.setCustomId(
`postChooseType.${interaction.user.id}.${fetchedReply.id}`
);

// Action Row
const AR = new ActionRowBuilder().addComponents(newSelectMenu);

// Add Components
reply.edit({
components: [AR],
});
// Deferred Reply
const deferredReply = await interaction.deferReply();

// Send Reply
const reply = await interaction.editReply({
content: "Posting System",
});

// Select Menu
const newSelectMenu = new StringSelectMenuBuilder()
.addOptions(
new SSMOB()
.setLabel("Option1")
.setDescription("The first option.")
.setValue("Option1")
)
.setCustomId(
`postChooseType.${interaction.user.id}.${fetchedReply.id}`
);

// Action Row
const AR = new ActionRowBuilder().addComponents(newSelectMenu);

// Add Components
reply.edit({
components: [AR],
});
I tried getting the reply ID from the deferredReply, but that returns a completely different ID to the one that get's sent. The only method that works is by setting the customId after the message was sent, and then editing the reply to add the selectMenu. I want to do this all before the event is sent.
6 replies
DIAdiscord.js - Imagine an app
Created by Turkinator on 7/25/2023 in #djs-questions
Error when trying to show modal after clicking button.
I'm trying to show a modal when the user clicks a button included in the reply, but I keep getting the 'InteractionAlreadyReplied' error.
// Dependencies
const { ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require("discord.js");

module.exports = async function (interaction) {
// Variables
let msg;
let collector;

// Buttons
const editDataButton = new ButtonBuilder()
.setCustomId("editDataButton")
.setLabel("EditID")
.setStyle(ButtonStyle.Primary);
const editDataRow = new ActionRowBuilder().addComponents(editDataButton);

// Modals
const editIDModal = new ModalBuilder()
.setCustomId("editIDModal")
.setTitle("EditID")

// Text Inputs
const IDInput = new TextInputBuilder()
.setCustomId("IDInput")
.setPlaceholder("ID")
.setStyle(TextInputStyle.Short)
.setMinLength(1)
.setMaxLength(20)
.setRequired(true);

// Set Modal Components
editIDModal.addComponents(IDInput);

msg = await interaction.reply({
content: "Please edit your account ID below.",
components: [editDataRow],
});

collector = msg.createMessageComponentCollector();

collector.on("collect", async (i) => {
if (i.customId == "editDataButton") {
await interaction.showModal(editIDModal)
}
});
};
// Dependencies
const { ButtonBuilder, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require("discord.js");

module.exports = async function (interaction) {
// Variables
let msg;
let collector;

// Buttons
const editDataButton = new ButtonBuilder()
.setCustomId("editDataButton")
.setLabel("EditID")
.setStyle(ButtonStyle.Primary);
const editDataRow = new ActionRowBuilder().addComponents(editDataButton);

// Modals
const editIDModal = new ModalBuilder()
.setCustomId("editIDModal")
.setTitle("EditID")

// Text Inputs
const IDInput = new TextInputBuilder()
.setCustomId("IDInput")
.setPlaceholder("ID")
.setStyle(TextInputStyle.Short)
.setMinLength(1)
.setMaxLength(20)
.setRequired(true);

// Set Modal Components
editIDModal.addComponents(IDInput);

msg = await interaction.reply({
content: "Please edit your account ID below.",
components: [editDataRow],
});

collector = msg.createMessageComponentCollector();

collector.on("collect", async (i) => {
if (i.customId == "editDataButton") {
await interaction.showModal(editIDModal)
}
});
};
I was told using deferReply was previously stopping it from working, so I switched it to a normal reply. Still getting the same error. P.S. There's other variables in there due to there being database management things, I removed them to clear up what's causing the issue.
17 replies