Markoudstaal / node-red-contrib-discord-advanced

Recieve, send, edit and delete Discord messages in node-red.
MIT License
47 stars 16 forks source link

DiscordAPIError: Unknown interaction #60

Closed CapricaBSG closed 1 year ago

CapricaBSG commented 1 year ago

Sometimes when the bot is responding to a command it will throw 'DiscordAPIError: Unknown interaction', it comes from discordInteraction.js. I have tested this with a 'test' command that does nothing except respond to a command. Sometimes it works sometimes it fails and when it does it throws the aforementioned error

Looking at discordInteraction.js

` registerCallback("interactionCreate", async interaction => { try { if (!matchInteractionType(interaction)) return;

      if (interaction.isCommand() || interaction.isMessageContextMenu()) {
        if (custom_id && custom_id.split(",").indexOf(interaction.commandName) < 0) return;
        await interaction.reply({ content: commandResponse, ephemeral: ephemeral });
      }
      else {
        if (custom_id && custom_id.split(",").indexOf(interaction.customId) < 0) return;
        await interaction.deferUpdate();
      }

      let message = {};
      message.payload = Flatted.parse(Flatted.stringify(interaction));
      message.payload.user = Flatted.parse(Flatted.stringify(interaction.user));

      if(interaction.member !== null) {
        message.payload.member = Flatted.parse(Flatted.stringify(interaction.member));
        message.payload.member.guild = Flatted.parse(Flatted.stringify(interaction.member.guild));
      }
      else {
        message.payload.member = null;
      }

      if (injectInteractionObject)
        message.interactionObject = interaction;

      if (interaction.isCommand() || interaction.isMessageContextMenu()) {
        message.payload.options = Flatted.parse(Flatted.stringify(interaction.options));
        message.payload.replyMessage = Flatted.parse(Flatted.stringify(await interaction.fetchReply()));
      }
      else {
        message.payload.message = Flatted.parse(Flatted.stringify(interaction.message));
        message.payload.message.author = Flatted.parse(Flatted.stringify(interaction.message.author));
      }

      node.send(message);
    } catch (error) {
      node.error(error);
      node.status({
        fill: "red",
        shape: "dot",
        text: error
      });
    }
  })`

I believe throw is at await interaction.reply({ content: commandResponse, ephemeral: ephemeral }).

it is a very annoying much, as a quicker fix I suggest sending the interaction obnject along with the node-red status so I am atleast able to respond to the command another way

javis86 commented 1 year ago

Do you have some heavy load on your node-red or network problems? Because this error comes when you don't reply the interaction in seconds

CapricaBSG commented 1 year ago

There is some heavy network usage. Is there any way to call deferUpdate() outside of this?

javis86 commented 1 year ago

An idea is to separate discord flow on a node-red instance and another instance with the heavy network usage.