我正在测试使用 Discord.js 为Discord Bot发送嵌入消息,这实际上是一个用于与Discord API交互的 node.js 模块。这是我用于机器人发送嵌入消息的代码:
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 Code IDE中收到此错误:
TypeError :(中级 值).setTitle(...)。setAuthor(...)。setColor(...)。setDescription(...)。setFooter(...)。setImage(...)。setThumbnail(... ).setTimestamp(...)。setURL(...)。addField(...)。addField(...)。addBlankField 不是功能
答案 0 :(得分:2)
当您查看documentation时,addBlankField()
类中没有MessageEmbed
函数,请检查您的discord.js
版本。
从v12.0.0开始,他们将RichEmbed
更改为MessageEmbed
。
答案 1 :(得分:0)
如果您想以其他方式添加空白字段,因为 discord.js v12 不支持 .addBlankField()
。你可以这样写:
.addField("** **", "** **")
这将添加一个标题几乎为空的字段和描述(发送嵌入后它们包含一个空格)
答案 2 :(得分:0)
试试这个:
const Discord = require('discord.js');
const client = new Discord.Client();
client.login('Your bot\'s token here');
client.on('ready', () => console.log('I\'m ready !');
client.on('message', message => {
const embed = new Discord.MessageEmbed()
.setTitle("This is your title, it can hold 256 characters")
.setAuthor("Author Name", "https://i.imgur.com/lm8s41J.png")
.setColor('WHITE')
.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)
.addField("Inline Field 3", "You can have a maximum of 25 fields.", true);
message.channel.send(embed);
如果这不起作用,我建议点击here
查看官方文档