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

Node.js开发Discord机器人/ping指令触发后无法接收输入超时问题求助

问题排查与修复方案

核心问题:未启用必要的网关意图

你当前使用的discord.js最新版本(v14+)中,接收服务器消息、读取消息内容都属于需要单独配置的网关意图,未正确配置的情况下机器人无法捕获到频道内的消息,自然会一直触发超时逻辑,需要完成两处配置:

  • 在Discord开发者后台的机器人设置页,找到「Privileged Gateway Intents」板块,开启Message Content Intent开关
  • 在初始化Discord Client的代码中,声明启用对应意图,示例如下:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds, // 斜杠指令必需的基础意图
    GatewayIntentBits.GuildMessages, // 接收服务器消息必需的意图
    GatewayIntentBits.MessageContent // 读取消息内容必需的特权意图
  ]
});

逻辑优化参考

你当前代码混用了await和.then(),可以统一用async/await写法降低逻辑出错概率,修改后的指令逻辑如下:

if (!interaction.isCommand()) return;

const { commandName } = interaction;

if (commandName === 'ping') {
    await interaction.reply('Why did you ping me?');
    const filter = m => interaction.user.id === m.author.id;

    try {
        const messages = await interaction.channel.awaitMessages({ 
            filter, 
            time: 15000, 
            max: 1, 
            errors: ['time'] 
        });
        await interaction.followUp(`You've entered: ${messages.first().content}`);
    } catch {
        await interaction.followUp('You did not enter any input!');
    }
}

其他检查点

  • 确认机器人在当前频道拥有「查看频道」「发送消息」「读取消息历史」的基础权限
  • 确认测试时发送的是普通文本消息,不是交互组件操作或者其他机器人指令

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 11:27:01