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

启用特定Intent后Discord.js报requestManager未定义的解决方法

解决Discord.js中TypeError: Cannot read properties of undefined (reading 'clearHashSweeper')报错问题

问题详情

运行Discord机器人时触发报错:

this.rest.requestManager.clearHashSweeper(); ^
TypeError: Cannot read properties of undefined (reading 'clearHashSweeper')

禁用IntentsBitField.Flags.MessageContent和IntentsBitField.Flags.GuildMembers后机器人恢复正常,需解决该问题。

相关代码:

const bot = new Client({
  intents: [
    IntentsBitField.Flags.MessageContent,
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMessages
    IntentsBitField.Flags.GuildMembers
  ],
  rest: {
    version: '10'
  }
});

使用版本:discord.js 14.12.0,Node.js 18.12.1

解决方案

  • 修复数组语法错误:你的intents数组中,IntentsBitField.Flags.GuildMessages末尾缺失逗号,导致数组解析异常,进而引发rest模块初始化失败。修正后的代码:
const bot = new Client({
  intents: [
    IntentsBitField.Flags.MessageContent,
    IntentsBitField.Flags.Guilds,
    IntentsBitField.Flags.GuildMessages, // 补上缺失的逗号
    IntentsBitField.Flags.GuildMembers
  ],
  rest: {
    version: '10'
  }
});
  • 开启后台权限Intent:登录Discord开发者平台,找到你的机器人应用,在「Bot」页面的「Privileged Gateway Intents」板块,开启Message Content Intent和Server Members Intent权限,否则即使代码正确,也会因权限不足出现异常。
  • 重新安装依赖(可选):如果修正语法后问题仍存在,尝试重新安装指定版本的discord.js:
npm uninstall discord.js
npm install discord.js@14.12.0

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 13:42:35