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) {
|
if (row) {
|
||||||
var data = row;
|
var data = row;
|
||||||
let lvl = data.lvl;
|
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({
|
interaction.reply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: `${user.tag}'s Rank`,
|
title: `${user.tag}'s Rank`,
|
||||||
fields: [{
|
fields: [{
|
||||||
|
name: "Rank",
|
||||||
|
value: `#${rank}`,
|
||||||
|
inline: true
|
||||||
|
},
|
||||||
|
{
|
||||||
name: "Level",
|
name: "Level",
|
||||||
value: data.lvl,
|
value: data.lvl,
|
||||||
inline: true
|
inline: true
|
||||||
|
@ -168,6 +187,8 @@ client.on("interactionCreate", async interaction => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case "leaderboard":
|
case "leaderboard":
|
||||||
await db.all(`SELECT * FROM levels ORDER BY totalXp DESC`, async (err, rows) => {
|
await db.all(`SELECT * FROM levels ORDER BY totalXp DESC`, async (err, rows) => {
|
||||||
|
@ -254,8 +275,7 @@ client.on("interactionCreate", async interaction => {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue