How to make embeds send correctly

Hey! I've been failing to make this embed send correctly. I'm trying to make code to sends multiple embeds whenever it reaches the limit (25), but I'm testing this code with a limit of 5 since I don't have > 25 data points.
2 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
Jasper
Jasper11mo ago
This is the current code so far.
async function setPointEmbed(message: Message<boolean>, client: Client, type: string) {
const embedsRequired = Math.ceil(Object.keys(global.points).length / 5);
console.log(embedsRequired);
if (embedsRequired === 0) {
message.channel.send("No points have been scored yet!");
return;
}
var tempPointEmbed = [];
for (var key in global.points) {
tempPointEmbed.push({ name: (await client.users.fetch(key)).username.toString(), value: points[key].toString() })
};
for (var i = 0; i < embedsRequired; i++) {
console.log("test")
if (i === 0) {
if (type === "final") { pointEmbed.setTitle("Final scores") }
else if (type === "current") { pointEmbed.setTitle("Current scores") }
else { throw Error("Invalid type of pointsDisplay entered") }
}
else { pointEmbed.setTitle(null)}
pointEmbed.setFields([]);
for (var j = 0; j < 5; j++) {
pointEmbed.addFields(tempPointEmbed[j + (i * 5)]);
}
message.channel.send({ embeds: [pointEmbed] });
}
async function setPointEmbed(message: Message<boolean>, client: Client, type: string) {
const embedsRequired = Math.ceil(Object.keys(global.points).length / 5);
console.log(embedsRequired);
if (embedsRequired === 0) {
message.channel.send("No points have been scored yet!");
return;
}
var tempPointEmbed = [];
for (var key in global.points) {
tempPointEmbed.push({ name: (await client.users.fetch(key)).username.toString(), value: points[key].toString() })
};
for (var i = 0; i < embedsRequired; i++) {
console.log("test")
if (i === 0) {
if (type === "final") { pointEmbed.setTitle("Final scores") }
else if (type === "current") { pointEmbed.setTitle("Current scores") }
else { throw Error("Invalid type of pointsDisplay entered") }
}
else { pointEmbed.setTitle(null)}
pointEmbed.setFields([]);
for (var j = 0; j < 5; j++) {
pointEmbed.addFields(tempPointEmbed[j + (i * 5)]);
}
message.channel.send({ embeds: [pointEmbed] });
}
Currently it does work, but it sends whenever a single .addFields is complete, which means it prints like this:
User1: x points
User1: x points
User1: x points
User2: x points
User1: x points
User2: x points
User1: x points
User2: x points
User3: x points
User1: x points
User2: x points
User3: x points
...
User6: y points
User6: y points
User6: y points
User7: y points
User6: y points
User7: y points
and so on What I want it to do is for it to print once as
User1: x points
User2: x points
User3: x points
User4: x points
User5: x points
User1: x points
User2: x points
User3: x points
User4: x points
User5: x points
User6: y points
User7: y points
User8: y points
User9: y points
User10: y points
User6: y points
User7: y points
User8: y points
User9: y points
User10: y points
and so on.