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

discord.js v14.11.0中GatewayIntentBits.MessageContent值为undefined求助

解决discord.js v14.11.0中GatewayIntentBits.MessageContent为undefined的问题
  • 检查导入语句是否正确
    必须从discord.js核心库导入GatewayIntentBits,避免从子模块导入导致枚举加载异常:

    // CommonJS
    const { GatewayIntentBits, Client } = require('discord.js');
    // ES模块
    import { GatewayIntentBits, Client } from 'discord.js';
    
  • 重装discord.js依赖
    依赖文件损坏可能导致枚举定义缺失,执行以下命令重装指定版本:

    npm uninstall discord.js
    npm install discord.js@14.11.0
    

    使用yarn或pnpm的话,替换对应包管理命令即可。

  • 清理冲突的类型定义(TypeScript用户)
    discord.js v14及以上自带完整类型,无需单独安装@types/discord.js,该包会和内置类型冲突,导致VS Code无法识别枚举:

    npm uninstall @types/discord.js
    

    操作完成后重启VS Code,类型提示即可恢复。

  • 验证枚举值并正确组合意图
    v14.11.0中GatewayIntentBits.MessageContent对应数值为32768,你可以通过打印确认是否正常加载:

    console.log(GatewayIntentBits.MessageContent); // 正常输出32768
    

    组合多个意图的正确写法:

    // 推荐:数组形式
    const client = new Client({
      intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent
      ]
    });
    // 位运算组合形式
    const client = new Client({
      intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent
    });
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 18:52:42