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

Discord密钥机器人TypeError报错排查与解决

问题描述

开发Discord密钥机器人时,反复触发两类TypeError报错:

  • UNCAUGHT EXCEPTION - keeping process alive: TypeError: Cannot read properties of undefined (reading 'client')
  • UNCAUGHT EXCEPTION - keeping process alive: TypeError: Cannot read properties of undefined (reading 'type')

尝试删除疑似问题代码后仍未解决,最终排查出是discord.js版本更新引发的兼容异常,将MessageEmbed替换为RichEmbed后问题修复。

报错关联代码
let a = "`"
const tosend = new Discord.MessageEmbed(client)
.setColor('#0099ff')
.setTitle('Whitelist')
.setDescription(`Your Key Your Key Is ${a}${key}${a}`)
.setFooter("TIP: Always save your key, you cannot use until registered")
完整错误栈
UNCAUGHT EXCEPTION - keeping process alive: TypeError: Cannot read properties of undefined (reading 'type')
    at MessageEmbed.setup (C:\Users\User\3D Objects\src\main\Bot\node_modules\discord.js\src\structures\MessageEmbed.js:29:22)
    at new MessageEmbed (C:\Users\User\3D Objects\src\main\Bot\node_modules\discord.js\src\structures\MessageEmbed.js:21:10)
    at module.exports.run (C:\Users\User\3D Objects\src\main\Bot\commands\whitelist.js:35:17)
    at Client.<anonymous> (C:\Users\User\3D Objects\src\main\Bot\index.js:48:34)
    at Client.emit (node:events:513:28)
    at MessageCreateHandler.handle (C:\Users\User\3D Objects\src\main\Bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\User\3D Objects\src\main\Bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:108:65)
    at WebSocketConnection.onPacket (C:\Users\User\3D Objects\src\Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:336:35)
    at WebSocketConnection.onMessage (C:\Users\User\3D Objects\src\Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:299:17)
    at WebSocket.onMessage (C:\Users\3D Objects\srcmain\Bot\node_modules\ws\lib\event-target.js:120:16)
解决方案

discord.js版本更新后,MessageEmbed的初始化逻辑或内部实现存在兼容问题,将代码中的Discord.MessageEmbed替换为Discord.RichEmbed即可修复报错。修改后的代码示例:

let a = "`"
const tosend = new Discord.RichEmbed()
.setColor('#0099ff')
.setTitle('Whitelist')
.setDescription(`Your Key Your Key Is ${a}${key}${a}`)
.setFooter("TIP: Always save your key, you cannot use until registered")

内容的提问来源于stack exchange,提问作者Im Okay At life

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 03:35:20