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

求助:Discord机器人报TypeError: Cannot read properties of undefined (reading 'GUILDS')

问题解决:TypeError: Cannot read properties of undefined (reading 'GUILDS')

错误原因

你在用discord.js v14版本开发机器人,但代码里用了旧版本的Intent写法:v14里GatewayIntentBits本身就是枚举对象,不存在FLAGS属性;同时客户端初始化配置的intents字段名应该是intents,不是GatewayIntentBits。这两个错误导致读取GatewayIntentBits.FLAGS时触发undefined报错。

修正后的代码

修改clientSettingsObject函数的返回内容:

function clientSettingsObject() {
  return {
    shards: "auto",
    allowedMentions: {
      parse: ["roles", "users", "everyone"],
      repliedUser: false,
    },
    failIfNotExists: false,
    partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
    intents: [ 
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildVoiceStates
    ]
  }
}

关键修改点

  • 把配置里的GatewayIntentBits键名改成intents,这是discord.js v14要求的正确字段名
  • 移除.FLAGS后缀,直接使用GatewayIntentBits枚举的大驼峰属性(比如GatewayIntentBits.Guilds)

修改后机器人就能正确加载所需的intents,该报错会被解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 10:00:54