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.
4 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 staff
Syjalo
Syjalo14mo ago
That's the interaction id. To get the message returned add fetchReply: true option.
qvgk
qvgkOP14mo ago
Is there a way for ephemeral messages? It worked for normal messages, but not for ephemeral ones
SpecialSauce
SpecialSauce14mo ago
You would use editReply() and specify the message id in the options.
Want results from more Discord servers?
Add your server