I have a rough idea on how to do this, but it doesn't seem to be working too well.
What I have already achieved is pulling all of the data necessary that needs ordered. What I need is a way to take all of that information and order it from the highest number to the lowest number, and then display that in a single embed - without the use of adding more fields. Ideally it should look something like the image included, except inside an embed. I want to be able to loop this so that it automatically updates the message every X amount of seconds with a message edit.
Each row is ordered from #1 to #20 with #1 having the most Points. This is in the [0123]
bit.
The code used to select data from the table is:
const [team, teamd, teame] = await pool.query("SELECT * FROM `performancetracker`.`leaderboard`");
The columns I have use for are TeamName
and Points
.
I've done something similar with the following code:
Object.keys(check).forEach(function(key) {
var row = check[key];
let name = row.TeamName
embed1.addField(`Team:`, `${name}`, true)
})
However, this adds fields to the embed, which I don't want. I'm not too sure how to go about creating an array or object that I can add to and edit later in the code while maintaining the ability to add it as a field in an embed. I'm not fluent with JavaScript, I'm still learning new things and finding new challenges.
CodePudding user response:
I'm not sure I can help you with the updating part because I don't fully understand the question, but you can do this for displaying the embed how you want:
let data;
Object.keys(check).forEach(() => {
var row = check[key];
let name = row.TeamName
data = `Team: ${name}\n`
})
embed1.addDescription(data)
I haven't tested this code, but it should work.