我正在使用 JavaScript 和 discord.js 制作一个 Discord 机器人。在那里,我想向频道发送 RichEmbed/MessageEmbed(我不知道它是如何调用的)。但是它没有发送 Embed,而是在 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)
Run Code Online (Sandbox Code Playgroud)
我已经搜索了答案,但似乎我是唯一遇到问题的人。
这是我使用的代码:
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)
Run Code Online (Sandbox Code Playgroud) 如何将 Node.js 中的文件作为字符串而不是缓冲区读取?我正在用 Node.js 编写一个程序。在那里我需要同步读取一个文件,但是如果我这样做,它会将它作为缓冲区而不是字符串返回。我的代码看起来像这样:
const fs = require('fs');
let content = fs.readFileSync('./foo.txt');
console.log(content) // actually logs it as a buffer
Run Code Online (Sandbox Code Playgroud)
请帮忙。