MegaMix_Craft
MegaMix_Craft

Reputation: 2210

"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  });
            }

Upvotes: 2

Views: 22358

Answers (2)

Pandie
Pandie

Reputation: 86

Your app needs to respond to the discord interaction within 3 seconds, otherwise the interaction is ended from Discord's end and you will get this error.

For slash commands, you can defer your response by executing the following:

await interaction.deferReply({ ephemeral: true });

This will then wait for you to run through whatever logic you need and follow up with:

interaction.editReply({ embeds: [embed] })

Note that you can only set the ephemeral flag on the initial response, so you need to know if it's going to be epherimal or not at the time you defer.

Also note, if you implement autocomplete for a slashcommand, you can't defer. You need to send your full response within the 3 seconds timeframe.

I would recommend reading the discordjs guide site, particularly this page.

Upvotes: 7

Eric Tsai
Eric Tsai

Reputation: 504

just using async function

For example:

await interaction.reply({ content: `Command you requested help for does not exist!`, ephemeral: true  });

Upvotes: 2

Related Questions