Discord.js DiscordAPIError[10062]:未知交互错误

问题描述 投票:0回答:1

我正在尝试使用discord.js 编写Discord 机器人,但在尝试使用嵌入按钮时遇到随机未知交互错误。

我相信这种情况可能会发生,因为交互需要很长时间才能响应。当我尝试单击嵌入上的按钮或使用选择菜单时,会发生这种情况。但是,我不确定如何解决这个问题。我在互动开始时已致电

interaction.deferReply()
,并使用
interaction.update()
更新消息。

这是我收到的错误:

/workspaces/miru/node_modules/@discordjs/rest/dist/index.js:722
      throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
            ^

DiscordAPIError[10062]: Unknown interaction
    at handleErrors (/workspaces/miru/node_modules/@discordjs/rest/dist/index.js:722:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async BurstHandler.runRequest (/workspaces/miru/node_modules/@discordjs/rest/dist/index.js:826:23)
    at async _REST.request (/workspaces/miru/node_modules/@discordjs/rest/dist/index.js:1266:22)
    at async StringSelectMenuInteraction.update (/workspaces/miru/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:233:5)
    at async InteractionCollector.<anonymous> (/workspaces/miru/commands/lists/list.js:156:9) {
  requestBody: {
    files: [],
    json: {
      type: 7,
      data: {
        content: undefined,
        tts: false,
        nonce: undefined,
        embeds: [
          {
            title: '5-toubun no Hanayome Movie',
            url: 'https://myanimelist.net/anime/48548',
            author: [Object],
            thumbnail: [Object],
            color: 16759283,
            fields: [Array],
            footer: [Object],
            timestamp: '2024-04-12T15:10:25.952Z'
          }
        ],
        components: undefined,
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: undefined,
        message_reference: undefined,
        attachments: undefined,
        sticker_ids: undefined,
        thread_name: undefined
      }
    }
  },
  rawError: { message: 'Unknown interaction', code: 10062 },
  code: 10062,
  status: 404,
  method: 'POST',
  url: 'https://discord.com/api/v10/interactions/1228361679293644890/aW50ZXJhY3Rpb246MTIyODM2MTY3OTI5MzY0NDg5MDpkQWhGNzNmcmEwZmZYZ2FvY1FobGxZbnJwYklKWEtYdVRnbzkzb3hlcmZaYWlxZVFLNzQzcUtmSGY1WVo1b1diRHIwZUVDMEhjYzJGR2ZZbFpVRmdDOTlTZm02cmdacTFuM21JQ1lFRWV3SjFDdmNDS0hEdjl3dXNIeGdqYVY5YQ/callback'
}

这是选择菜单和按钮的收集器:

const collector = interaction.channel.createMessageComponentCollector({ time: 900000 });

    collector.on('collect', async i => {
      if (i.customId === 'select_anime') {
        currentIndex = parseInt(i.values[0]);
        await i.update({ embeds: [embeds[currentIndex]] });
      } else if (['previous', 'next'].includes(i.customId)) {
        await i.update({ embeds: [embeds[currentIndex]] });
      } else if (['prev_menu', 'next_menu'].includes(i.customId)) {
        if (i.customId === 'prev_menu' && currentMenuIndex > 0) {
          currentMenuIndex--;
        } else if (i.customId === 'next_menu' && currentMenuIndex < chunkedAnimeList.length - 1) {
          currentMenuIndex++;
        }
        rowSelectMenu.setComponents(createSelectMenu(chunkedAnimeList[currentMenuIndex], currentMenuIndex));
        menuNavigationButtons.setComponents(createMenuNavigationButtons().components);
        await i.update({ components: [rowSelectMenu, menuNavigationButtons] });
      }
    });

我在这里打电话

interaction.deferReply()
:

async execute(interaction) {
    await interaction.deferReply();

发送命令时发送第一个嵌入。其余的在用户使用选择菜单后编辑:

// Send the initial message
    await interaction.editReply({
      embeds: [embeds[currentIndex]],
      components: [rowSelectMenu, menuNavigationButtons]
    });

我尝试寻找解决方案,但找不到任何东西。我也尝试将

i.update()
更改为使用
i.editReply()
但是,这不起作用并返回另一个错误。如有任何帮助,我们将不胜感激!

discord.js
1个回答
0
投票

interaction.deferUpdate() 然后interaction.update()

© www.soinside.com 2019 - 2024. All rights reserved.