简体   繁体   English

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

[英]why does it say .setDescription is not a function? (RichEmbed in JavaScript)

I'm creating an embed for my command /quotes which is to be used for my discord bot. 我正在为我的命令/quotes创建一个嵌入,这将用于我的discord bot。

Here's the code: 这是代码:

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);
}

I keep receiving an error on my console that .setDescription is not a function 我一直在控制台上收到一个错误,即.setDescription不是一个函数

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

The problem is that you don't have a semicolon after the line q3 = " -- www.quotesgate.com" so it pastes the next line right after it. 问题是你在q3 = " -- www.quotesgate.com"之后没有分号,所以它会在它之后粘贴下一行。 So it basically becomes 所以它基本上变成了

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

which won't work ofcourse. 哪个不会有效。 I'm assuming you want to call the setDescription and addField on the embed so you need to change your code to the following: 我假设您要在嵌入时调用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);
}
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);

}

Done! 完成! :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM