'"DiscordAPIError: Unknown interaction" when trying to send info about a command
I'm making a slash command to send a user info about command when they use /help but when I add more than one command I just get this error:
E:\v13\node_modules\discord.js\src\rest\RequestHandler.js:298
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Unknown interaction
at RequestHandler.execute (E:\v13\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (E:\v13\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
at async CommandInteraction.reply (E:\v13\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:98:5) {
method: 'post',
path: '/interactions/[EDITED]/callback',
code: 10062,
httpStatus: 404,
requestData: {
json: {
type: 4,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: 'Help Menu ➞ test',
type: 'rich',
description: null,
url: null,
timestamp: 0,
color: 3447003,
fields: [Array],
thumbnail: null,
image: null,
author: null,
footer: [Object]
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
}
},
files: []
}
}
My code:
interaction.client.commands.each((cmd) => {
if(cmd.name == args[0].toLowerCase() || cmd.aliases.includes(args[0].toLowerCase())) {
embed.setTitle("Help Menu" + " " + "➞" + " " + `${cmd.name}`)
embed.addField("**Description**", `${cmd.description}`, false)
embed.addField("**Usage**", `${cmd.usage}`, true)
embed.addField("**Aliases**", `${cmd.alias}`, true)
embed.addField("**Examples**", `${cmd.examples}`, true)
interaction.reply({ embeds: [embed], ephemeral: false });
} else {
interaction.reply({ content: `Command you requested help for does not exist!`, ephemeral: true });
}
})
It is working just fine when I have only one command in commands folder, but if I add second command I can use this command once and if I use it again - my bot crashes! Also it can't find 2nd command and only can see first one
Update 1: I changed my code a bit and now it can find 2nd command but if I try to search for command by its alias, it sends me command info and crash the bot with the same error! Basically I just added:
if(!found) {
interaction.reply({ content: `Command you requested help for does not exist!`, ephemeral: true });
} else {
interaction.reply({ embeds: [embed], ephemeral: false });
}
Solution 1:[1]
Probably in the future someone will provide me a better answer but as temp. solution I use .catch(err => {}) (interaction.reply({}).catch(err => {})) which is fixing my code!
Solution 2:[2]
just using async function
For example:
await interaction.reply({ content: `Command you requested help for does not exist!`, ephemeral: true });
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MegaMix_Craft |
| Solution 2 | Eric Tsai |
