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

新手求助:ReferenceError: ChannelType is not defined错误排查

问题解决:ReferenceError: ChannelType is not defined

这个报错的核心原因是你使用了ChannelType这个枚举类型,但没有正确导入它,或者你的Discord.js版本不支持这个写法。下面分两种情况解决:

情况1:你用的是Discord.js v14及以上版本

v14开始Discord.js把频道类型改成了枚举,必须先导入才能用:

  • 如果是CommonJS(require写法),在代码开头加:
    const { ChannelType } = require('discord.js');
    
  • 如果是ES Modules(import写法),在代码开头加:
    import { ChannelType } from 'discord.js';
    
  • 要是还没装最新版,先执行命令更新:
    npm install discord.js@latest
    

情况2:你用的是Discord.js v13及更早版本

这些版本里没有ChannelType枚举,直接用字符串判断频道类型就行:

if (!channel || channel.type !== 'GUILD_TEXT') {
  // 你的原有逻辑代码
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 15:37:32