Unknown interaction, sometimes

The problem is that sometimes it works and sometimes it generates an error, and I've already tried it without using defer, same result. How my Main class register commands
export default class MyClient extends Client {
constructor(options) {
super(options);

this.slashCommandsArray = [];
this.loadEvents();
this.loadSlashCommands();
};

async registerCommands() {
await this.application.commands.set(this.slashCommandsArray, "guild_id");
};
}
export default class MyClient extends Client {
constructor(options) {
super(options);

this.slashCommandsArray = [];
this.loadEvents();
this.loadSlashCommands();
};

async registerCommands() {
await this.application.commands.set(this.slashCommandsArray, "guild_id");
};
}
My interactionCreate Class
export default class InteractionCreate extends ReadyClient {
constructor(client) {
super(client, {
name: "interactionCreate"
})
}
execute = async(interaction) => {
const commandName = interaction.commandName;
const command = this.client.slashCommandsArray.find(cmd => cmd.name === commandName);

if(!command) return;

await interaction.deferReply();
await command.execute(interaction);
}
}
export default class InteractionCreate extends ReadyClient {
constructor(client) {
super(client, {
name: "interactionCreate"
})
}
execute = async(interaction) => {
const commandName = interaction.commandName;
const command = this.client.slashCommandsArray.find(cmd => cmd.name === commandName);

if(!command) return;

await interaction.deferReply();
await command.execute(interaction);
}
}
my test command
export default class Ping extends SlashCommands {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Reply with pong")
});
};
execute = async(interaction) => {
await interaction.editReply("Pong!");
};
};
export default class Ping extends SlashCommands {
constructor(client) {
super(client, {
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Reply with pong")
});
};
execute = async(interaction) => {
await interaction.editReply("Pong!");
};
};
4 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!
black
blackOP9mo ago
Isn't it an error related to interactionCreate or something like that? in theory even if my connection was very bad, with defer it wouldn't be a problem
{
requestBody: { files: undefined, json: { type: 5, data: { flags: undefined } } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
....
{
requestBody: { files: undefined, json: { type: 5, data: { flags: undefined } } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
....
defer is not the problem, I tried without it too, just with await interaction.reply in the ping command file and I get the same result, sometimes it works and sometimes it gives the error
node:events:492
throw er; // Unhandled 'error' event
^

DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.deferReply (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/[email protected]/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:69:5)
at async MyClient.execute (file:///home/junior-light/Desktop/discord-js-test-0/src/events/Interaction/InteractionCreate.js:20:9)
Emitted 'error' event on MyClient instance at:
at emitUnhandledRejectionOrErr (node:events:397:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: { files: undefined, json: { type: 5, data: { flags: undefined } } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1224707594568994958/aW50ZXJhY3Rpb246MTIyNDcwNzU5NDU2ODk5NDk1ODp4U0t4YkxBS3VxZUxlT2xONklCN1NtUmxCOEE1M1ZmMGZqejZXOE42bjdMcXpXU1gzcWw3eURYMzg1RFR0QWNGZFVsbHdJTkxDTVQ4U1R4S2NQMnpOVTVkQ0t2ZlhLZnpvQVZZdFE5b1hUR0g2N0pBS3hyUHZTZHhmdElMZXJ5Tg/callback'
}
node:events:492
throw er; // Unhandled 'error' event
^

DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.deferReply (/home/junior-light/Desktop/discord-js-test-0/node_modules/.pnpm/[email protected]/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:69:5)
at async MyClient.execute (file:///home/junior-light/Desktop/discord-js-test-0/src/events/Interaction/InteractionCreate.js:20:9)
Emitted 'error' event on MyClient instance at:
at emitUnhandledRejectionOrErr (node:events:397:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: { files: undefined, json: { type: 5, data: { flags: undefined } } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1224707594568994958/aW50ZXJhY3Rpb246MTIyNDcwNzU5NDU2ODk5NDk1ODp4U0t4YkxBS3VxZUxlT2xONklCN1NtUmxCOEE1M1ZmMGZqejZXOE42bjdMcXpXU1gzcWw3eURYMzg1RFR0QWNGZFVsbHdJTkxDTVQ4U1R4S2NQMnpOVTVkQ0t2ZlhLZnpvQVZZdFE5b1hUR0g2N0pBS3hyUHZTZHhmdElMZXJ5Tg/callback'
}
I'm still thinking it strange that the problem is my connection yes sometimes oh, just name is wrong, its extends simple EventMap class
export default class EventMap {
constructor(client, options) {
this.client = client,
this.name = options.name,
this.once = options.once || false
};
};
export default class EventMap {
constructor(client, options) {
this.client = client,
this.name = options.name,
this.once = options.once || false
};
};
not is the problem
async loadEvents(src="./src/events") {
const eventsFolders = readdirSync(src, { withFileTypes: true }).reduce((previousValue, nextValue) => {
return nextValue.isDirectory() ? [...previousValue, nextValue.name] : previousValue;
}, []);
for(const eventFolder of eventsFolders) {
const eventsFiles = readdirSync(`${src}/${eventFolder}`).filter(eventFile => eventFile.endsWith(".js"));
for(const eventFile of eventsFiles) {
const eventPath = join(process.cwd(), src, eventFolder, eventFile);
const { default: EventMap } = await import(eventPath);
const event = new EventMap(this);
if(event.once) {
this.once(event.name, event.execute);
};
if(!event.once) {
this.on(event.name, event.execute);
}
}
}
};
async loadEvents(src="./src/events") {
const eventsFolders = readdirSync(src, { withFileTypes: true }).reduce((previousValue, nextValue) => {
return nextValue.isDirectory() ? [...previousValue, nextValue.name] : previousValue;
}, []);
for(const eventFolder of eventsFolders) {
const eventsFiles = readdirSync(`${src}/${eventFolder}`).filter(eventFile => eventFile.endsWith(".js"));
for(const eventFile of eventsFiles) {
const eventPath = join(process.cwd(), src, eventFolder, eventFile);
const { default: EventMap } = await import(eventPath);
const event = new EventMap(this);
if(event.once) {
this.once(event.name, event.execute);
};
if(!event.once) {
this.on(event.name, event.execute);
}
}
}
};
yes, in MyClient in constructor of MyClient?
this.loadEvents()
this.loadEvents()
i use readdirSync in loadEvents and loadSlashCommands If I can't use await in the constructor, then there's not much I can do about it It's very random, sometimes I turn on the bot, try to use some command and Unknow Interaction, sometimes I turn on the bot and manage to use it a few times and then it fails using Htop in linux, my cpu it is normal, network issues i can't monitoring Then I'll try to upload it to a VPS or another machine and leave feedback here
Eternal
Eternal9mo ago
You could run "ping" in the background and watch for spikes in ping. When thr bot crashes, you can look at the ping logs to see if there was a massive spike in ping or not
black
blackOP9mo ago
@Qjuh Update, i just pass the bot project to Docker, and slash commands has work normally now, and in my normal machine, same host, the problem probably came from my system
Want results from more Discord servers?
Add your server