#returns null instead of 0
38 messages · Page 1 of 1 (latest)
const { MessageEmbed, Discord } = require('discord.js');
const { QuickDB } = require('quick.db');
const db = new QuickDB();
exports.run = async (client, message, args) => {
//bro :(
const array = (await db.startsWith(`point_${message.guild.id}`)).sort((a,b) => b.value - a.value);; // sorted balances
let content = "";
// create the leaderboard message
for(let i = 0; i < 10 && i < array.length; i++) {
let user = message.guild.members.cache.get(array[i].id.split('_')[2]).displayName; // plexie>>>>>igp
content += `${i+1}. ${user} - ${array[i].value}\n` // plexie>>>igp
}
const embed = new MessageEmbed()
.setTitle(`Guild Point Leaderboard!`)
.setColor("#303136")
.setDescription(content)
.setFooter(`Requested by ${client.user.tag}`)
.setTimestamp()
message.channel.send({embeds: [embed]});
}
exports.name = "lb"
current lb code..
You can use ?? to make it 0
For example:
value ?? 0 if value is null it will be 0 instead. Now tbh, I find it quite weird because you shouldn't have null values coming from quick.db
The other question about emojis.
You can make an array of them like
const emotes = ["1", "2", "3"]
And you can use them in your loop with
emotes[i]
how about when i only need first 3 to be emote
rest normal
huh?
bro i think thats when there are less than 3 ppl
in lb
i said i want like this
No it is not
gld medal ani - 150
Silver medl - 50
bronze medal - 10
4 -zelak- 5
5- 2
It should be in the loop
0 < 3 true
1 < 3 true
2 < 3 true
3 < 3 false
4 < 3 false
...
This is exactly what you want
The number changing is i
The counter of the loop
Since that will be in a if statement
The code that will be in that if statement will only be executed on the first 3
That is not for when it's less than 3 people. Not at all
You add the emote
i cn directly write
Like do the if condition and in that if condition add the emote to content
Well that won't work. You don't need a else either
The else would make the code repetitive
Oh you want to keep numbers too, you will need a else than yeah but it could be shorter
How?
if (i < 3) {
content += emotes[i];
else {
content += i+1;
}
content += ` - ${user} - ${array[i].value ?? 0}`;
``` like that
You can even change 3 to emotes.length like that if you add emotes in the array (or remove one), it will still work and you won't have to manually change that number
Oh alr thank you so much
I'll try that tmrw
Gotta sleep now