Reputation: 23
I want to use a dynamic name variable inside a loop but it shows the error "EmbedMessage is not defined". 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
});
}
Upvotes: 0
Views: 481
Reputation: 3005
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
});
}
Upvotes: 2