Discord Bot生成错误:“未定义消息”

时间:2019-10-23 23:57:00

标签: javascript discord.js

好吧,我试图为我的机器人(也称为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});```

1 个答案:

答案 0 :(得分:0)

您似乎缺少onMessage侦听器。

尝试此代码:

const Discord = require(`discord.js`);
const client = new Discord.Client();
client.login(<token>);
client.on(`message`, function (message) {
    const embed = new Discord.RichEmbed()
      .setTitle("This is your title, it can hold 256 characters");
      //Reducted the rest of the (.setColor, .setFooter, etc) to save space
    message.channel.send({embed});
});

假设您知道从何处获得<token>,则此处的代码正是您所需要的。