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

discord.js报错:Module 'discord.js' 无导出成员'Intents'求助

解决Discord.js报错:Module 'discord.js' has no exported member 'Intents'

这个错误的核心原因是discord.js版本不同,Intents的导入和使用方式存在差异,同时你的代码缺少必要的导入语句和环境变量加载步骤,以下分版本给出修复方案:

版本1:discord.js v14及以上

v14开始移除了Intents导出,改用GatewayIntentBits,同时意图常量的命名规则改为驼峰复数形式:

import dotenv from 'dotenv';
import { Client, GatewayIntentBits } from 'discord.js';

// 加载.env文件中的环境变量
dotenv.config();

const bot = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages
    ]
});

bot.on('ready', ()=>{
    console.log("ready")
})

bot.login(process.env.TOKEN)

版本2:discord.js v13及以下

v13及以下仍使用Intents,但需要确保正确导入,同时注意意图常量的复数命名:

import dotenv from 'dotenv';
import { Client, Intents } from 'discord.js';

// 加载.env文件中的环境变量
dotenv.config();

const bot = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES // 原代码少了末尾的s,需修正
    ]
});

bot.on('ready', ()=>{
    console.log("ready")
})

bot.login(process.env.TOKEN)

额外注意事项

  • 执行npm list discord.js命令可查看当前使用的discord.js版本,匹配对应方案
  • 必须调用dotenv.config(),否则无法读取.env文件中的TOKEN,导致登录失败

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 11:06:18