【发布时间】:2020-02-20 06:18:40
【问题描述】:
好吧,我正在尝试为我的机器人(又名 Jarvis)创建一个嵌入,当我启动它时,它显示以下错误:无法执行任务 command.js:ReferenceError:未定义消息
我已经完成了所有工作,尝试使用其他人在 Discord 附属网站上创建的基础来更改命令,但最终没有找到解决方案。
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});```
【问题讨论】:
-
此代码块是否在消息侦听器中执行?我的猜测是它不是,或者您将消息变量命名为与正常使用不同
-
您能否尝试改进我的代码以适应引用的这种模式?
-
如果没有看到您的其余代码,我就忍不住了。您添加的代码的唯一问题(据我所知)是
message.channel.send(),它只能在消息侦听器上下文中完成,或者从那里传递给函数。您需要确保您的代码知道消息是什么。
标签: javascript discord.js