提问者:小点点

discord.js bot的代码响应错误“TypeError:”


我正在测试使用Discord.js为Discord机器人发送嵌入消息,Discord.js基本上是一个Node.js模块,用于与Discord的API交互。这是我用于bot发送嵌入消息的代码:

const Discord = require('discord.js');
const embed = new Discord.RichEmbed()
    .setTitle("This is your title, it can hold 256 characters")
    .setAuthor("Author Name", "https://i.imgur.com/lm8s41J.png")
    .setColor(0x00AE86)
    .setDescription("This is the main body of text, it can hold 2048 characters.")
    .setFooter("This is the footer text, it can hold 2048 characters", "http://i.imgur.com/w1vhFSR.png")
    .setImage("http://i.imgur.com/yVpymuV.png")
    .setThumbnail("http://i.imgur.com/p2qNFag.png")
    .setTimestamp()
    .setURL("https://discord.js.org/#/docs/main/indev/class/RichEmbed")
    .addField("This is a field title, it can hold 256 characters",
        "This is a field value, it can hold 1024 characters.")
    .addField("Inline Field", "They can also be inline.", true)
    .addBlankField(true)
    .addField("Inline Field 3", "You can have a maximum of 25 fields.", true);

  message.channel.send({embed});

当我运行代码时,在Visual Studio代码IDE中会出现以下错误:

TypeError:(中间值)。SetTitle(。。。)。SetAuthor(。。。)。SetColor(。。。)。SetDescription(。。。)。SetFooter(。。。)。SetImage(。。。)。SetThumbnail(。。。)。SetTimestamp(。。。)。SetURL(。。。)。AddField(。。。)。AddBlankField不是函数


共1个答案

匿名用户

MessageEmbed类中没有AddBlankField()函数当您查看文档时,请检查您的Discord.js版本。

从V12.0.0开始,他们将richembed更改为messageembed