Unknown Interaction error

i've tried all things to fix the issue but none of them worked. Even chatgpted it but still. Anyone knows why?
client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
await interactionHandlers.handleCommand(interaction, db);
} else if (interaction.isButton()) {
await interactionHandlers.handleButton(interaction, db);
} else if (interaction.isStringSelectMenu()) {
await interactionHandlers.handleStringSelect(interaction, db);
} else if (interaction.isModalSubmit()) {
await interactionHandlers.handleModal(interaction, db);
}
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
await interactionHandlers.handleCommand(interaction, db);
} else if (interaction.isButton()) {
await interactionHandlers.handleButton(interaction, db);
} else if (interaction.isStringSelectMenu()) {
await interactionHandlers.handleStringSelect(interaction, db);
} else if (interaction.isModalSubmit()) {
await interactionHandlers.handleModal(interaction, db);
}
});
3 Replies
d.js toolkit
d.js toolkit11h ago
renza
renzaOP11h ago
async function handleCommand(interaction, db) {
if (interaction.commandName === 'verify') {

// FIRST — prevent Unknown Interaction
await interaction.deferReply({ ephemeral: true });

const allowedChannel = "1433978702097547374";

// Restrict to specific channel
if (interaction.channel.id !== allowedChannel) {
return interaction.editReply(
"❌ You can only use **/verify** in <#1433978702097547374>."
);
}

// Account age check
const accountAge = Date.now() - interaction.user.createdTimestamp;
const minAge = 30 * 24 * 60 * 60 * 1000;

if (accountAge < minAge) {
const days = Math.floor(accountAge / (24 * 60 * 60 * 1000));

return interaction.editReply(
`❌ **Your Discord account is too new to verify.**\n` +
`You must wait **30 days**.\n` +
`(Current age: **${days} days**)`
);
}

const username = interaction.options.getString('username');
const code = interaction.options.getString('code');
const discordId = interaction.user.id;

// Promisified DB
const queryAsync = (sql, params) => {
return new Promise((resolve, reject) => {
db.query(sql, params, (err, results) => {
if (err) reject(err);
else resolve(results);
});
});
};

// Check user
const checkQuery = `
SELECT id FROM players
WHERE username = ?
AND code = ?
AND (discordid IS NULL OR discordid = '')
AND NOT EXISTS (SELECT 1 FROM players WHERE discordid = ?)
LIMIT 1
`;

let results;
try {
results = await queryAsync(checkQuery, [username, code, discordId]);
} catch (err) {
console.error(err);
return interaction.editReply("❌ Database error. Please try again later.");
}

// No match → fail
if (!results || results.length === 0) {
return interaction.editReply(
`❌ **Verification failed.**\n` +
`Make sure:\n` +
`• Username is correct\n` +
`• Code is correct\n` +
`• Your Discord is not already linked`
);
}

// Update user
const updateQuery = `
UPDATE players
SET discordid = ?, verified = 1
WHERE username = ? AND code = ?
LIMIT 1
`;
await queryAsync(updateQuery, [discordId, username, code]);

// Try to set nickname
try {
await interaction.member.setNickname(username);
} catch (err) {
console.warn("Nickname change failed:", err);
}

// FINAL message
return interaction.editReply({
content:
`✅ **Verification Successful!**\n` +
`<@${discordId}> is now linked to **${username}**.\n\n` +
`Welcome to **Los Santos Team Deathmatch!** 🔥`,
ephemeral: false
});
}
}
async function handleCommand(interaction, db) {
if (interaction.commandName === 'verify') {

// FIRST — prevent Unknown Interaction
await interaction.deferReply({ ephemeral: true });

const allowedChannel = "1433978702097547374";

// Restrict to specific channel
if (interaction.channel.id !== allowedChannel) {
return interaction.editReply(
"❌ You can only use **/verify** in <#1433978702097547374>."
);
}

// Account age check
const accountAge = Date.now() - interaction.user.createdTimestamp;
const minAge = 30 * 24 * 60 * 60 * 1000;

if (accountAge < minAge) {
const days = Math.floor(accountAge / (24 * 60 * 60 * 1000));

return interaction.editReply(
`❌ **Your Discord account is too new to verify.**\n` +
`You must wait **30 days**.\n` +
`(Current age: **${days} days**)`
);
}

const username = interaction.options.getString('username');
const code = interaction.options.getString('code');
const discordId = interaction.user.id;

// Promisified DB
const queryAsync = (sql, params) => {
return new Promise((resolve, reject) => {
db.query(sql, params, (err, results) => {
if (err) reject(err);
else resolve(results);
});
});
};

// Check user
const checkQuery = `
SELECT id FROM players
WHERE username = ?
AND code = ?
AND (discordid IS NULL OR discordid = '')
AND NOT EXISTS (SELECT 1 FROM players WHERE discordid = ?)
LIMIT 1
`;

let results;
try {
results = await queryAsync(checkQuery, [username, code, discordId]);
} catch (err) {
console.error(err);
return interaction.editReply("❌ Database error. Please try again later.");
}

// No match → fail
if (!results || results.length === 0) {
return interaction.editReply(
`❌ **Verification failed.**\n` +
`Make sure:\n` +
`• Username is correct\n` +
`• Code is correct\n` +
`• Your Discord is not already linked`
);
}

// Update user
const updateQuery = `
UPDATE players
SET discordid = ?, verified = 1
WHERE username = ? AND code = ?
LIMIT 1
`;
await queryAsync(updateQuery, [discordId, username, code]);

// Try to set nickname
try {
await interaction.member.setNickname(username);
} catch (err) {
console.warn("Nickname change failed:", err);
}

// FINAL message
return interaction.editReply({
content:
`✅ **Verification Successful!**\n` +
`<@${discordId}> is now linked to **${username}**.\n\n` +
`Welcome to **Los Santos Team Deathmatch!** 🔥`,
ephemeral: false
});
}
}
ill send it here when i received the error again it was a player trying to use the /verify command i guess
d.js docs
d.js docs11h 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

Did you find this page helpful?