关于不和谐嵌入(JAVASCRIPT)

时间:2020-08-30 20:18:54

标签: javascript node.js discord.js

因此,我目前正在为不和谐的机器人编写代码,但是我遇到了嵌入问题。因此,我想发送一个显示一定数量对象属性的Embed作为内联字段,因此我考虑制作一个for循环并将.addField放入其中,类似这样。

let object = {
  "name1" : "value1",
  "name2" : "value2",
  "name3" : "value3"
}

const exampleEmbed = new Discord.MessageEmbed()
  //... other embeds elements
  for (let i of object) {
    .addField("Inline Field", i, true) 

    //So for each property of the object created above it will add
    // a Inline Field to the Embed with the value of i, the variable that holds the properties of the
    // object.
}

唯一的问题是它不起作用。因此,我在这里询问解决问题的替代方法。在此先感谢

1 个答案:

答案 0 :(得分:0)

就像@secretlyrice注释中所建议的那样,而不是执行.addField(...),而是引用嵌入变量,就像exampleEmbed.addField(...)一样。