Javascript 对嵌入消息进行编码
我正在浏览discord.js指南,在嵌入我的消息时发现了这段代码 代码如下Javascript 对嵌入消息进行编码,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,我正在浏览discord.js指南,在嵌入我的消息时发现了这段代码 代码如下 client.on('message', message => { // If the message is "how to embed" if (message.content === 'how to embed') { // We can create embeds using the MessageEmbed constructor // Read
client.on('message', message => {
// 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 MessageEmbed()
.setTitle('A slick little embed')
.setColor(0xff0000)
.setDescription('Hello, this is a slick embed!');
message.channel.send(embed);
}
});
但是,当我运行该命令时,会收到以下错误消息
const embed=新消息嵌入
^
你能帮我进一步吗?我自己找到了答案,你只需要将此添加到代码中
const Discord = require('discord.js');
const { MessageEmbed } = require("discord.js");
然后您可以继续使用代码
client.on('message', message => {
// 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 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);
}
});
为我工作,希望也为你工作我想你有const Discord=requirediscord.js;在脚本的开头?您可以添加const MessageEmbed=Discord.MessageEmbed;下面是Discord.MessageEmbed,或者在脚本中使用Discord.MessageEmbed。仍然不起作用。我收到一条错误消息againChris的代码应该起作用,如果您将圆括号添加到Discord.MessageEmbed。仍然是相同的错误消息谢谢您帮助找到答案
client.on('message', message => {
// 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 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);
}
});