Components timeout causing "Unknown Message" error on ephemeral messages

Hey all, I did a bit of research before posting this but I'm still a bit confused, I'm wondering what would be the best way (if possible) to disable components on ephemeral messages. I'm currently trying to disable select menus after a timeout period using my component handler, but I'm getting a DiscordAPIError[10008]: Unknown Message error. My current setup does majority of the component handling within my components.js file, the rest being within the command files itself. The handler disables components after a certain time (2 minutes in my case). The error occurs in the disableComponents function when trying to edit ephemeral messages. The message exists when the timeout triggers, but the edit fails. I've considered just letting the components expire naturally, but I'd prefer to have them visibly disabled for better UX. I've also tried checking if the message is ephemeral before attempting to edit, but I'm not sure where to extend from this other then just ignoring the error. Here's the relevant code from my component handler:
async function disableComponents(message) {
try {
const disabledRows = message.components.map(row => {
const newRow = ActionRowBuilder.from(row);
newRow.components = newRow.components.map(component => {
if (component instanceof ButtonBuilder) {
return ButtonBuilder.from(component).setDisabled(true);
} else if (component instanceof StringSelectMenuBuilder) {
return StringSelectMenuBuilder.from(component).setDisabled(true);
}
return component;
});
return newRow;
});

await message.edit({ components: disabledRows });

messageTimeouts.delete(message.id);
const key = generateCommandKey(message);
cleanupCommandMap(key);
} catch (error) {
console.error(`Error disabling components for message ${message.id}:`, error);
}
}
async function disableComponents(message) {
try {
const disabledRows = message.components.map(row => {
const newRow = ActionRowBuilder.from(row);
newRow.components = newRow.components.map(component => {
if (component instanceof ButtonBuilder) {
return ButtonBuilder.from(component).setDisabled(true);
} else if (component instanceof StringSelectMenuBuilder) {
return StringSelectMenuBuilder.from(component).setDisabled(true);
}
return component;
});
return newRow;
});

await message.edit({ components: disabledRows });

messageTimeouts.delete(message.id);
const key = generateCommandKey(message);
cleanupCommandMap(key);
} catch (error) {
console.error(`Error disabling components for message ${message.id}:`, error);
}
}
Let me know if you want to see any other portions of my code :)
3 Replies
d.js toolkit
d.js toolkit6mo 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
Steve
Steve6mo ago
you just can't edit ephemeral messages
Stranger
StrangerOP6mo ago
thank you, managed to fix my issue!

Did you find this page helpful?