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

Discord排位机器人报错‘Application did not respond’求助

问题排查与修复方案

核心错误:未处理Slash命令交互

你注册了/sett Slash命令,但代码中没有对应的interactionCreate事件监听逻辑,导致Discord无法收到机器人的响应,从而触发「Application did not respond」错误。

修复步骤:

添加Slash命令的交互处理代码:

client.on('interactionCreate', async (interaction) => {
  if (!interaction.isCommand()) return;

  const { commandName } = interaction;

  if (commandName === 'sett') {
    try {
      // 先发送临时回复避免超时
      await interaction.deferReply({ ephemeral: true });
      
      const channel = await interaction.guild.channels.create('Queue', { type: 'GUILD_TEXT' });

      const joinButton = new Discord.MessageButton()
        .setCustomId('join_queue')
        .setLabel('Join Queue')
        .setStyle('PRIMARY');

      const leaveButton = new Discord.MessageButton()
        .setCustomId('leave_queue')
        .setLabel('Leave Queue')
        .setStyle('DANGER');

      const row = new Discord.MessageActionRow()
        .addComponents(joinButton, leaveButton);

      const queueMessage = await channel.send({ content: 'Click a button to join or leave the queue:', components: [row] });

      queues.set('queue_message', queueMessage.id);
      queues.set('queue_channel', channel.id);

      // 更新回复告知设置完成
      await interaction.editReply('Queue setup completed.');
    } catch (err) {
      console.error('Error during setup:', err);
      await interaction.editReply('There was an error during setup.');
    }
  }
});

其他代码问题与优化建议

  • 前缀命令逻辑错误:你的前缀是-,但messageCreate中判断command === '-sett'是错误的——args.shift()已经去掉了前缀,输入-sett时command实际为sett,应改为command === 'sett'才能触发前缀命令。
  • 缺少按钮交互处理:创建的Join/Leave按钮没有对应的点击事件监听,点击后机器人无响应,需补充:
client.on('interactionCreate', async (interaction) => {
  if (!interaction.isButton()) return;

  const { customId } = interaction;

  if (customId === 'join_queue') {
    // 此处添加加入队列的业务逻辑,比如存储用户ID到队列
    await interaction.reply({ content: '已加入队列!', ephemeral: true });
  } else if (customId === 'leave_queue') {
    // 此处添加离开队列的业务逻辑
    await interaction.reply({ content: '已离开队列!', ephemeral: true });
  }
});
  • Intent权限不足:若需要读取消息内容,需在Discord开发者门户开启「Message Content Intent」,同时更新client的intents配置:
const client = new Discord.Client({
  intents: [
    Discord.GatewayIntentBits.Guilds,
    Discord.GatewayIntentBits.GuildMessages,
    Discord.GatewayIntentBits.MessageContent // 新增该权限
  ]
});
  • 敏感信息硬编码风险:不要直接将YOUR_BOT_TOKEN、YOUR_APPLICATION_ID等敏感信息写在代码中,建议使用dotenv包管理环境变量,避免泄露。

验证流程

  1. 在Discord开发者门户确认已开启所有必要的Intent权限
  2. 替换代码中的占位符为真实的令牌、应用ID和服务器ID
  3. 重启机器人,确保Slash命令重新注册成功
  4. 测试/sett命令,确认不再出现「Application did not respond」错误

内容的提问来源于stack exchange,提问作者Med Fourat Baya

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 15:35:00