discord.js 机器人缺少模块?
Posted
技术标签:
【中文标题】discord.js 机器人缺少模块?【英文标题】:Missing module for discord.js bot? 【发布时间】:2021-08-09 02:45:57 【问题描述】:我对 Debian9 上的不和谐启动有疑问,我正在尝试运行我的代码,但 VPS 向我抛出了这个错误。以前,我在另一个 VPS 上通常有这个机器人,一切正常,但现在它不起作用。我不知道我是否缺少任何模块或节点和 npm 安装不当。
TypeError: fields.flat is not a function
at Function.normalizeFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:443:8)
at MessageEmbed.addFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:259:42)
at Client.client.on (/home/bot/main.js:368:22)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (/home/bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
TypeError: fields.flat is not a function
at Function.normalizeFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:443:8)
at MessageEmbed.addFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:259:42)
at Client.client.on (/home/bot/main.js:201:14)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (/home/bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
ReferenceError: guildMember is not defined
at Client.client.on (/home/bot/main.js:446:9)
at Client.emit (events.js:198:13)
at Object.module.exports [as GUILD_MEMBER_UPDATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js:18:16)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:198:13)
at Receiver.receiverOnMessage (/home/bot/node_modules/ws/lib/websocket.js:835:20)
at Receiver.emit (events.js:198:13)
TypeError: fields.flat is not a function
at Function.normalizeFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:443:8)
at MessageEmbed.addFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:259:42)
at Client.client.on (/home/bot/main.js:368:22)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (/home/bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
TypeError: fields.flat is not a function
at Function.normalizeFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:443:8)
at MessageEmbed.addFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:259:42)
at Client.client.on (/home/bot/main.js:368:22)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (/home/bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
TypeError: fields.flat is not a function
at Function.normalizeFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:450:8)
at MessageEmbed.addFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:266:42)
at Client.client.on (/home/bot/main.js:368:22)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (/home/bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
ReferenceError: guildMember is not defined
at Client.client.on (/home/bot/main.js:446:9)
at Client.emit (events.js:198:13)
at GuildMemberUpdateAction.handle (/home/bot/node_modules/discord.js/src/client/actions/GuildMemberUpdate.js:30:51)
at Object.module.exports [as GUILD_MEMBER_UPDATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js:4:36)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:198:13)
at Receiver.receiverOnMessage (/home/bot/node_modules/ws/lib/websocket.js:825:20)
TypeError: fields.flat is not a function
at Function.normalizeFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:450:8)
at MessageEmbed.addFields (/home/bot/node_modules/discord.js/src/structures/MessageEmbed.js:266:42)
at Client.client.on (/home/bot/main.js:368:22)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (/home/bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/bot/node_modules/ws/lib/event-target.js:132:16)
我不知道如何处理它,我是否缺少安装的模块?
【问题讨论】:
快速搜索得到这个:***.com/questions/60934727/… 简而言之,你的node版本可能已经过时了,不支持discord.js要求的Array.flat()
【参考方案1】:
.flat()
method 仅适用于 Node 11 及更高版本,discord.js v12 需要 Node 12.x 或更高版本。确保您使用的是最新版本。在guide 上阅读更多相关信息。
【讨论】:
以上是关于discord.js 机器人缺少模块?的主要内容,如果未能解决你的问题,请参考以下文章
当我使用节点启动机器人时,为啥 discord.js 模块出现错误?
故障上托管的不和谐机器人错误:找不到模块'discord.js'