Error in translate command "Unknown interaction"

Hello, this is a code for a translate command via contextmenu command, i cant figure out what in the code is causing this error. This error occurs sometimes. Can anyone with more coding experience than me see what could be the issue.
Error while replying to interaction: DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async MessageContextMenuCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.run (/home/container/slashCommands/context/translate.js:156:7)
at async Client.<anonymous> (/home/container/events/interactionCreate.js:77:13) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1220771689877733456/aW50ZXJhY3Rpb246MTIyMDc3MTY4OTg3NzczMzQ1NjpuSXdBaHNURHBIMUxlNVJja3RaVzVCaXJzeTU3bWNhMTBmR2lVeUo2eG5RMm1jT1pZaGcxVENjSDl6ZnU5bTFtV1VzWmZ6bGNpRkd1SkdPTUJoRnFjZFN0UWRycUUzTkJTUWFQNzg0amQ1TURRS0pvS0FzQnFJcmJ0RFB0MmhMQg/callback'
}
Error while replying to interaction: DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/home/container/node_modules/discord.js/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async MessageContextMenuCommandInteraction.reply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.run (/home/container/slashCommands/context/translate.js:156:7)
at async Client.<anonymous> (/home/container/events/interactionCreate.js:77:13) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1220771689877733456/aW50ZXJhY3Rpb246MTIyMDc3MTY4OTg3NzczMzQ1NjpuSXdBaHNURHBIMUxlNVJja3RaVzVCaXJzeTU3bWNhMTBmR2lVeUo2eG5RMm1jT1pZaGcxVENjSDl6ZnU5bTFtV1VzWmZ6bGNpRkd1SkdPTUJoRnFjZFN0UWRycUUzTkJTUWFQNzg0amQ1TURRS0pvS0FzQnFJcmJ0RFB0MmhMQg/callback'
}
9 Replies
d.js toolkit
d.js toolkit9mo 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
d.js docs
d.js docs9mo ago
Common causes of DiscordAPIError[10062]: Unknown interaction: - Initial response took more than 3 seconds ➞ defer the response *. - Wrong interaction object inside a collector. - Two processes handling the same command (the first consumes the interaction, so it won't be valid for the other instance) * Note: you cannot defer modal or autocomplete value responses
BakeWithMe
BakeWithMeOP9mo ago
@astro its probably because of "Initial response took more than 3 seconds", but when i do deferreply, the ephemeral doesnt work anymore
astro
astro9mo ago
What do you mean "doesnt work anymore"??
BakeWithMe
BakeWithMeOP9mo ago
ephemeral true doesnt show up as a view only message anymore then
astro
astro9mo ago
Does it reply as a regular message? Like viewable by everyone?
BakeWithMe
BakeWithMeOP9mo ago
yes the translations, but not the error messages
astro
astro9mo ago
You need to do .editReply, not .reply if a response is defered
BakeWithMe
BakeWithMeOP9mo ago
but then everything will be in ephemeral: true? This is my code now, i think deferreply fixed my error but now the error messages arent in ephemeral: true. these two: 'ℹ️ This text was already recently translated, please look back in chat' 'ℹ️ This message seems to be in English already or it might just be gibberish I cannot translate'
run: async (client, interaction) => {
try {
await interaction.deferReply();

const selectedMessage = await interaction.channel.messages.fetch(interaction.targetId);

// Detect the language of the original message
const detectedLanguageAbbreviation = (await translate(selectedMessage.content)).from.language.iso.toUpperCase();
const detectedLanguage = getLanguageName(detectedLanguageAbbreviation);

// Check if the detected language is English
if (detectedLanguageAbbreviation === 'EN') {
return await interaction.editReply({ content: 'ℹ️ This message seems to be in **English** already or it might just be gibberish I cannot translate', ephemeral: true });
}

// Check if the message was recently translated
if (recentlyTranslatedMessages[selectedMessage.id] && Date.now() - recentlyTranslatedMessages[selectedMessage.id] < 300000) {
return await interaction.editReply({ content: 'ℹ️ This text was already recently translated, please look back in chat', ephemeral: true });
}

// Store the current timestamp as the time the message was translated
recentlyTranslatedMessages[selectedMessage.id] = Date.now();

// Translate the message content to English
const translateResult = await translate(selectedMessage.content, { to: 'en' });

// Create a hyperlink to the original message content
const originalMessageLink = `[${selectedMessage.cleanContent}](${selectedMessage.url})`;

// Create an embed to display the translation
const translateEmbed = new EmbedBuilder()
.setTitle(`${detectedLanguage} to English`)
.setDescription(`❔ **${selectedMessage.author}** said: ${originalMessageLink}`)
.addFields(
{ name: '☑️ Translation:', value: translateResult.text }
)
.setColor(interaction.client.config.embedColor);

await new Promise(resolve => setTimeout(resolve, 1000));

// Send the translated message as a response
await interaction.editReply({ embeds: [translateEmbed], ephemeral: interaction.options.ephemeral });
} catch (e) {
console.error(e);
await interaction.editReply({ content: 'An error occurred while processing your command.', ephemeral: true });
}
},
};
run: async (client, interaction) => {
try {
await interaction.deferReply();

const selectedMessage = await interaction.channel.messages.fetch(interaction.targetId);

// Detect the language of the original message
const detectedLanguageAbbreviation = (await translate(selectedMessage.content)).from.language.iso.toUpperCase();
const detectedLanguage = getLanguageName(detectedLanguageAbbreviation);

// Check if the detected language is English
if (detectedLanguageAbbreviation === 'EN') {
return await interaction.editReply({ content: 'ℹ️ This message seems to be in **English** already or it might just be gibberish I cannot translate', ephemeral: true });
}

// Check if the message was recently translated
if (recentlyTranslatedMessages[selectedMessage.id] && Date.now() - recentlyTranslatedMessages[selectedMessage.id] < 300000) {
return await interaction.editReply({ content: 'ℹ️ This text was already recently translated, please look back in chat', ephemeral: true });
}

// Store the current timestamp as the time the message was translated
recentlyTranslatedMessages[selectedMessage.id] = Date.now();

// Translate the message content to English
const translateResult = await translate(selectedMessage.content, { to: 'en' });

// Create a hyperlink to the original message content
const originalMessageLink = `[${selectedMessage.cleanContent}](${selectedMessage.url})`;

// Create an embed to display the translation
const translateEmbed = new EmbedBuilder()
.setTitle(`${detectedLanguage} to English`)
.setDescription(`❔ **${selectedMessage.author}** said: ${originalMessageLink}`)
.addFields(
{ name: '☑️ Translation:', value: translateResult.text }
)
.setColor(interaction.client.config.embedColor);

await new Promise(resolve => setTimeout(resolve, 1000));

// Send the translated message as a response
await interaction.editReply({ embeds: [translateEmbed], ephemeral: interaction.options.ephemeral });
} catch (e) {
console.error(e);
await interaction.editReply({ content: 'An error occurred while processing your command.', ephemeral: true });
}
},
};
no the translation not, only the error messages should be ephemeral (see above) thank you
Want results from more Discord servers?
Add your server