为什么说.setDescription不是函数? (RichEmbed在JavaScript中)

时间:2019-04-06 15:36:58

标签: javascript node.js discord.js

我正在为命令/quotes创建一个嵌入,该嵌入将用于我的不和谐机器人。

代码如下:

if(cmd === `${prefix}quotes`){

  quotes = new Discord.RichEmbed();
  q1 = "  -- Andres Iniesta";
  q2 = "  -- French Poverb";
  q3 = "  -- www.quotesgate.com"

  .setDescription("**__Here are some inspirational quotes!__**")
  .setColor("#319786")
  .addField("**Some people like you, some people don't. In the end, you just have to be yourself.**". q1)
  .addField("**Wherever life plants you, bloom with grace**", q2)
  .addField("Don’t forget you’re human. It’s okay to have a meltdown. Just don’t unpack and live there. Cry it out. Then refocus on where you’re headed", q3)

  return message.channel.send(quotes);
}

我在控制台上始终收到错误消息,表明.setDescription不是函数

/ | TomatoHeadIdiot is now active in 4 servers!
(node:7448) UnhandledPromiseRejectionWarning: TypeError: "  -- www.quotesgate.com".setDescription is not a function

2 个答案:

答案 0 :(得分:0)

问题是,在q3 = " -- www.quotesgate.com"行之后没有分号,因此它将下一行粘贴在其后。所以基本上变成了

q3 = "  -- www.quotesgate.com".setDescription("**__Here are some inspirational quotes!__**")

这当然不会起作用。我假设您想调用嵌入中的setDescriptionaddField,因此您需要将代码更改为以下内容:

if(cmd === `${prefix}quotes`){

  q1 = "  -- Andres Iniesta";
  q2 = "  -- French Poverb";
  q3 = "  -- www.quotesgate.com";

  quotes = new Discord.RichEmbed()
    .setDescription("**__Here are some inspirational quotes!__**")
    .setColor("#319786")
    .addField("**Some people like you, some people don't. In the end, you just have to be yourself.**". q1)
    .addField("**Wherever life plants you, bloom with grace**", q2)
    .addField("Don’t forget you’re human. It’s okay to have a meltdown. Just don’t unpack and live there. Cry it out. Then refocus on where you’re headed", q3);

  return message.channel.send(quotes);
}

答案 1 :(得分:0)

if(cmd === `${prefix}quotes`){

  quotes = new Discord.RichEmbed();
  q1 = "  -- Andres Iniesta";
  q2 = "  -- French Poverb";
  q3 = "  -- www.quotesgate.com";

  quotes.setDescription("**__Here are some inspirational quotes!__**");
  quotes.setColor("#319786");
  quotes.addField("**Some people like you, some people don't. In the end, you just have to be yourself.**". q1);
  quotes.addField("**Wherever life plants you, bloom with grace**", q2);
  quotes.addField("Don’t forget you’re human. It’s okay to have a meltdown. Just don’t unpack and live there. Cry it out. Then refocus on where you’re headed", q3);

  return message.channel.send(quotes);

}

完成! :-)