简体   繁体   English

Discord JS 消息嵌入动态变量名

[英]Discord JS Message embed dynamic variable name

I want to use a dynamic name variable inside a loop but it shows the error "EmbedMessage is not defined".我想在循环内使用动态名称变量,但它显示错误“未定义 EmbedMessage”。 Is there a way to do it?有没有办法做到这一点?

const EmbedMessage1 = {
 title: '__TITLE1__',
 description: '**First embed message**',
 //etc.
};
const EmbedMessage2 = {
 title: '__TITLE2__',
 description: '**Second embed message**',
 //etc.
};
//etc.

for (let i = 1; i < 4; i++) {
 message.channel.send({ embed: EmbedMessage[i] }).then((msg) => {
  //function
 });
}

You should use an array of embeds instead of naming your variables like that.您应该使用一个嵌入数组,而不是像这样命名您的变量。

const embeds = [
 {
  title: '__TITLE1__',
  description: '**First embed message**',
  //etc.
 },
 {
  title: '__TITLE2__',
  description: '**Second embed message**',
  //etc.
 },
];
//etc.

for (let i = 1; i < 4; i++) {
 message.channel.send({ embed: embeds[i] }).then((msg) => {
  //function
 });
}

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

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