【发布时间】:2020-06-07 19:08:36
【问题描述】:
我是不和谐机器人的新手,不太了解,所以也许我很愚蠢。
我尝试嵌入消息,但收到错误 (node:15832) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function。我尝试从 discord 网站复制示例并使用它,但仍然出现此错误!。
client.on('message', message => {
// deal with messages / commands
// If the message is "how to embed"
if (message.content === 'how to embed') {
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/master/class/MessageEmbed
const embed = new Discord.MessageEmbed()
// Set the title of the field
.setTitle('A slick little embed')
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Hello, this is a slick embed!');
// Send the embed to the same channel as the message
message.channel.send(embed);
}
});
错误:
(node:15832) UnhandledPromiseRejectionWarning: TypeError: fields.flat is not a function
at Function.normalizeFields (C:\Users\leinb\Documents\coding\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:443:8)
at MessageEmbed.setup (C:\Users\leinb\Documents\coding\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:77:91)
at new MessageEmbed (C:\Users\leinb\Documents\coding\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:18:10)
at embedLikes.map.e (C:\Users\leinb\Documents\coding\DiscordBot\node_modules\discord.js\src\structures\APIMessage.js:164:40)
at Array.map (<anonymous>)
at APIMessage.resolveData (C:\Users\leinb\Documents\coding\DiscordBot\node_modules\discord.js\src\structures\APIMessage.js:164:31)
at TextChannel.send (C:\Users\leinb\Documents\coding\DiscordBot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:166:62)
at Client.client.on.message (C:\Users\leinb\Documents\coding\DiscordBot\index.js:36:19)
at Client.emit (events.js:198:13)
at MessageCreateAction.handle (C:\Users\leinb\Documents\coding\DiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
(node:15832) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:15832) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
-
你用的是什么版本的node和discord.js?
标签: node.js discord.js