Add rank to /rank, i'm dumb
This commit is contained in:
parent
6390f718fa
commit
d785cf72ad
24
index.js
24
index.js
|
@ -140,10 +140,29 @@ client.on("interactionCreate", async interaction => {
|
|||
if (row) {
|
||||
var data = row;
|
||||
let lvl = data.lvl;
|
||||
let rank;
|
||||
// Calculate rank
|
||||
await db.all(`SELECT * FROM levels ORDER BY totalXp DESC`, async (err, rows) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
if (rows) {
|
||||
let rank = 0;
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
if (rows[i].id === user.id) {
|
||||
rank = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
interaction.reply({
|
||||
embeds: [{
|
||||
title: `${user.tag}'s Rank`,
|
||||
fields: [{
|
||||
name: "Rank",
|
||||
value: `#${rank}`,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: "Level",
|
||||
value: data.lvl,
|
||||
inline: true
|
||||
|
@ -168,6 +187,8 @@ client.on("interactionCreate", async interaction => {
|
|||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "leaderboard":
|
||||
await db.all(`SELECT * FROM levels ORDER BY totalXp DESC`, async (err, rows) => {
|
||||
|
@ -254,8 +275,7 @@ client.on("interactionCreate", async interaction => {
|
|||
ephemeral: true
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
break;
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue