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

Discord API报错10062: Unknown interaction,用户积分获取失败求助

解决DiscordAPIError[10062]: Unknown interaction问题并实现积分打印

错误根源

Discord强制要求交互请求必须在3秒内得到响应。你的代码中await findUser(interaction.member.id)是数据库查询操作,若该操作耗时超过3秒,Discord会判定此交互已失效,后续调用interaction.reply时就会触发"Unknown interaction"错误。

修复方案

1. 先延迟响应交互

在执行数据库查询前,调用interaction.deferReply()告知Discord正在处理请求,这会将响应超时窗口延长至15分钟,足够完成数据库操作。

2. 执行查询并打印积分

获取用户积分后直接打印到控制台,再通过editReply更新之前延迟的响应内容。

修改后的代码示例:

} else if (interaction.customId === "giverole") {
  // 先延迟响应,避免超时
  await interaction.deferReply({ ephemeral: true });

  // 执行数据库查询
  const userPoints = await findUser(interaction.member.id);
  
  // 打印积分到控制台
  console.log(`用户 ${interaction.member.user.tag} 的积分:${userPoints}`);

  // 更新延迟的回复
  await interaction.editReply({
    content: `Give role! 你的积分是 ${userPoints}`,
    ephemeral: true,
  });
};

额外注意事项

  • 检查findUser函数是否存在性能瓶颈,比如未优化的SQL语句或缺失的索引,必要时优化数据库查询速度。
  • 同一交互只能调用一次reply,后续更新需使用editReply或followUp(使用followUp前必须先完成deferReply或reply操作)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 15:13:11