You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.js v13出现Unknown Interaction错误 交互仅显示Bot is thinking

问题原因与解决方案

问题根因

  • 你的interactionCreate全局事件中,对所有下拉菜单(SelectMenu)交互不加判断就先执行了await interaction.deferReply(),但help菜单的组件收集器中使用interaction.update()响应用户操作,二者触发了Discord交互响应规则冲突:
    • Discord规定每个交互只能响应1次,且调用deferReply()后交互会被标记为「已延迟回复」状态,仅能使用editReply()/followUp()方法完成后续响应,无法再调用update()方法修改原消息
    • 全局事件先调用deferReply()后,即使该交互不属于反应角色功能,也已经被标记为已处理,后续收集器再尝试响应就会返回Unknown Interaction错误,同时因为你没有后续回复逻辑,页面就会一直显示Bot is thinking...
  • 之前功能正常是因为该全局SelectMenu处理逻辑是后续新增/生效的,和help菜单的组件收集器逻辑产生了冲突。

修复方案

修改interactionCreate事件中的下拉菜单处理逻辑,先判断当前交互是否属于反应角色功能,再决定是否调用延迟回复,不属于反应角色的交互直接放行交给对应收集器处理即可。

修改后的代码片段:

//Reaction Roles Handling
if (interaction.isSelectMenu()) {
    // 先查询是否为反应角色交互
    const reactionPanel = await reactionRoles.findOne({
        guildId: interaction.guildId,
        'reactionPanels.customId': `${interaction.customId}`,
    });
    // 不是反应角色交互直接返回,不做任何处理,交给收集器响应
    if (!reactionPanel) return;
    // 确认是反应角色交互后再执行延迟回复
    await interaction.deferReply();
    // 剩余原有反应角色处理逻辑保持不变
    const roleId = interaction.values[0];
    const role = interaction.guild.roles.cache.get(roleId);
    if (!role) return;
    const memberRoles = interaction.member.roles;
    const hasRole = memberRoles.cache.has(roleId);
    if (hasRole) {
        memberRoles.remove(roleId);
        interaction.followUp({
            content: `${role.name} has been removed from you`,
            ephemeral: true,
        });
    } else {
        memberRoles.add(roleId);
        interaction.followUp({
            content: `${role.name} has been added to you`,
            ephemeral: true,
        });
    }
}

可选优化

给所有交互响应代码包裹try/catch块,避免因网络波动、交互超时等偶发问题抛出未捕获的全局错误导致机器人异常退出,示例:

try {
    await interaction.update({ embeds: [categoryEmbed] });
} catch (err) {
    // 可根据需求打印日志,不抛出全局错误即可
    console.error('交互响应失败:', err);
}

内容的提问来源于stack exchange,提问作者iamk3v

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 20:06:03