【问题标题】:UnhandledPromiseRejectionWarning from MessageEmbed来自 MessageEmbed 的 UnhandledPromiseRejectionWarning
【发布时间】: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


【解决方案1】:

您需要将 Node.JS 更新到版本 12.x,您可以这样做here
这也位于他们 GitHub 上的 README.md 中。

【讨论】:

  • 我已经听过这个警告二十次了,从没想过要检查我的 node.js 版本。我想这就是我需要的。谢谢!
  • 没问题 :) 也谢谢你!
猜你喜欢
  • 1970-01-01
  • 2021-07-16
  • 2021-01-19
  • 1970-01-01
  • 2019-04-08
  • 2019-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多