Update index.js
This commit is contained in:
73
index.js
73
index.js
@@ -124,6 +124,9 @@ client.on('interactionCreate', async (interaction) => {
|
||||
);
|
||||
}
|
||||
|
||||
// Before adding fields to the embed, initialize a counter
|
||||
let totalFields = 0;
|
||||
|
||||
// Add profile fields dynamically
|
||||
const profileFields = [];
|
||||
|
||||
@@ -156,6 +159,7 @@ client.on('interactionCreate', async (interaction) => {
|
||||
|
||||
if (profileFields.length > 0) {
|
||||
embed.addFields(profileFields);
|
||||
totalFields += profileFields.length;
|
||||
}
|
||||
|
||||
// Set badge image if available
|
||||
@@ -165,8 +169,11 @@ client.on('interactionCreate', async (interaction) => {
|
||||
|
||||
// Dynamically add game statistics
|
||||
const games = playerData.stats?.games;
|
||||
if (games && Object.keys(games).length > 0) {
|
||||
embed.addFields({ name: '\u200B', value: '**Game Statistics**' });
|
||||
if (games && Object.keys(games).length > 0 && totalFields < 25) {
|
||||
if (totalFields + 1 <= 25) {
|
||||
embed.addFields({ name: '\u200B', value: '**Game Statistics**' });
|
||||
totalFields += 1;
|
||||
}
|
||||
|
||||
for (const [gameName, gameData] of Object.entries(games)) {
|
||||
if (
|
||||
@@ -211,19 +218,41 @@ client.on('interactionCreate', async (interaction) => {
|
||||
inline: true,
|
||||
});
|
||||
|
||||
if (statsFields.length > 0) {
|
||||
embed.addFields(
|
||||
{ name: '\u200B', value: `**${gameName} - ${modeName}**` },
|
||||
...statsFields
|
||||
);
|
||||
// Calculate the number of fields to be added
|
||||
const fieldsToAdd = 1 + statsFields.length; // 1 for the section header
|
||||
|
||||
// Check if adding these fields would exceed the limit
|
||||
if (totalFields + fieldsToAdd > 25) {
|
||||
// You can choose to skip adding these fields or break the loop
|
||||
break; // Stops adding more fields
|
||||
}
|
||||
|
||||
// Add the section header
|
||||
embed.addFields({
|
||||
name: '\u200B',
|
||||
value: `**${gameName} - ${modeName}**`,
|
||||
});
|
||||
totalFields += 1;
|
||||
|
||||
// Add the stats fields
|
||||
embed.addFields(statsFields);
|
||||
totalFields += statsFields.length;
|
||||
|
||||
// Check after each addition
|
||||
if (totalFields >= 25) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalFields >= 25) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add teams dynamically
|
||||
const teams = playerData.teams;
|
||||
if (teams && Object.keys(teams).length > 0) {
|
||||
if (teams && Object.keys(teams).length > 0 && totalFields < 25) {
|
||||
const teamList = Object.values(teams)
|
||||
.map(
|
||||
(team) =>
|
||||
@@ -231,15 +260,22 @@ client.on('interactionCreate', async (interaction) => {
|
||||
)
|
||||
.join('\n');
|
||||
|
||||
embed.addFields(
|
||||
const teamsField = [
|
||||
{ name: '\u200B', value: '**Teams**' },
|
||||
{ name: 'Team List', value: teamList || 'No teams available' }
|
||||
);
|
||||
{ name: 'Team List', value: teamList || 'No teams available' },
|
||||
];
|
||||
|
||||
// Check if adding these fields would exceed the limit
|
||||
const fieldsToAdd = teamsField.length;
|
||||
if (totalFields + fieldsToAdd <= 25) {
|
||||
embed.addFields(teamsField);
|
||||
totalFields += fieldsToAdd;
|
||||
}
|
||||
}
|
||||
|
||||
// Add recent matches dynamically
|
||||
const matches = playerData.matches;
|
||||
if (matches && Object.keys(matches).length > 0) {
|
||||
if (matches && Object.keys(matches).length > 0 && totalFields < 25) {
|
||||
const matchList = Object.values(matches)
|
||||
.sort((a, b) => new Date(b.start_time) - new Date(a.start_time)) // Sort by date descending
|
||||
.slice(0, 3) // Limit to recent 3 matches
|
||||
@@ -252,10 +288,17 @@ client.on('interactionCreate', async (interaction) => {
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
embed.addFields(
|
||||
const matchesField = [
|
||||
{ name: '\u200B', value: '**Recent Matches**' },
|
||||
{ name: 'Match History', value: matchList || 'No recent matches' }
|
||||
);
|
||||
{ name: 'Match History', value: matchList || 'No recent matches' },
|
||||
];
|
||||
|
||||
// Check if adding these fields would exceed the limit
|
||||
const fieldsToAdd = matchesField.length;
|
||||
if (totalFields + fieldsToAdd <= 25) {
|
||||
embed.addFields(matchesField);
|
||||
totalFields += fieldsToAdd;
|
||||
}
|
||||
}
|
||||
|
||||
// Add action buttons
|
||||
|
||||
Reference in New Issue
Block a user