discord.js MessageEmbedfields.flat不是函数 [英] discord.js MessageEmbed fields.flat is not a function
问题描述
我正在使用JavaScript和discord.js制作Discord机器人。在那里,我想向频道发送RichEmbed / MessageEmbed(我不知道如何称呼)。
I am making a Discord bot using JavaScript and discord.js. There, I want to send a RichEmbed/MessageEmbed (I don't know how it's called) to a channel. Instead of sending an Embed though, it threw an error inside discord.js.
TypeError: fields.flat is not a function
at Function.normalizeFields (D:\discord-bot\node_modules\discord.js\src\structures\MessageEmbed.js:436:8)
at MessageEmbed.addFields (D:\discord-bot\node_modules\discord.js\src\structures\MessageEmbed.js:252:42)
at commands.forEach.command (D:\discord-bot\src\js\core\commands\commandManager.js:55:19)
at Array.forEach (<anonymous>)
at helloWorldEmbed (D:\discord-bot\src\js\core\commands\commandManager.js:54:18)
at Object.call (D:\discord-bot\src\js\core\commands\commandManager.js:29:13)
at Client.client.on (D:\discord-bot\src\js\core\bot.js:16:49)
at Client.emit (events.js:182:13)
at MessageCreateAction.handle (D:\discord-bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (D:\discord-bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
我已经在寻找答案,但似乎我是唯一遇到问题的人。
I searched already for an answer, but it seems like I'm the only person having trouble with it.
这是我使用的代码:
const embed = new MessageEmbed()
.setTitle('Hello World')
.setDescription('This is a test.')
.setColor('#3498db')
quotes.forEach(quote => {
embed.addField(quote.name, quote.description, true)
})
message.channel.send('Hello world.', embed)
推荐答案
如注释中所述,更新Node.js可解决此问题。 Discord.js v12需要12.0.0或更高版本,因为它用于提高效率的方法(例如错误中的 Array#flat()
)在旧版本中不存在
As discussed in comments, updating Node.js solves the issue. Discord.js v12 requires 12.0.0 or newer because of the methods (like Array#flat()
in the error) it uses for efficiency which don't exist in older versions.
这篇关于discord.js MessageEmbedfields.flat不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!