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

Discord.js v14机器人命令生效却提示“应用未响应”问题求助

问题原因与解决方案

Discord 的 slash 命令(交互)有强制要求:必须在3秒内对 interaction 对象进行响应,否则平台会判定应用未响应并弹出提示。你只调用了 channel.send() 发送嵌入到指定频道,但没有对用户发起的交互本身做任何回复,导致超时触发错误。而 interaction.reply() 本身就是对交互的响应,所以不会出现这个问题。

解决方法

不管你是否需要给用户显示反馈,都必须先在3秒内完成对交互的响应,再执行发送到其他频道的操作。以下是两种常用写法:

1. 立即给用户发送反馈(推荐)

先回复交互告知用户命令已执行,再发送嵌入到目标频道:

async execute(interaction) {
  // 先回复交互,避免超时,ephemeral: true 仅发起命令的用户可见
  await interaction.reply({ content: "规则公告已成功发送到指定频道!", ephemeral: true });

  // 获取目标频道
  const targetChannel = interaction.guild.channels.cache.get('你的目标频道ID');
  if (!targetChannel) return interaction.editReply({ content: "找不到指定的目标频道!" });

  // 构建嵌入消息
  const embed = new EmbedBuilder()
    .setTitle("服务器规则")
    .setDescription("这里填写具体的规则内容")
    .setColor('#0099ff');

  // 发送嵌入到目标频道
  await targetChannel.send({ embeds: [embed] });
}

2. 延迟处理(适合耗时操作)

如果你的操作可能超过3秒,先调用 deferReply() 告知Discord正在处理,后续再更新回复:

async execute(interaction) {
  // 延迟回复,标记为正在处理
  await interaction.deferReply({ ephemeral: true });

  // 模拟耗时操作(比如从数据库拉取规则)
  await new Promise(resolve => setTimeout(resolve, 4000));

  const targetChannel = interaction.guild.channels.cache.get('你的目标频道ID');
  if (!targetChannel) return interaction.editReply({ content: "找不到指定的目标频道!" });

  const embed = new EmbedBuilder()
    .setTitle("服务器规则")
    .setDescription("这里填写具体的规则内容")
    .setColor('#0099ff');

  await targetChannel.send({ embeds: [embed] });

  // 更新回复,告知用户操作完成
  await interaction.editReply({ content: "规则公告已发送!" });
}

关键提醒

  • 所有 slash 命令都必须在3秒内调用 interaction.reply()、interaction.deferReply() 或 interaction.deferUpdate() 中的一个,否则必然触发“应用未响应”错误。
  • 如果不需要保留用户可见的回复,也可以在发送完成后调用 interaction.deleteReply() 删除之前的回复。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 15:45:37