#returns null instead of 0

38 messages · Page 1 of 1 (latest)

languid meteor
#

i did like if(pp === null) pp = 0
still it returns null
instead of 0
and second thing i wanna know is ,how do i do if i wanna add emojis in front of users in lb
🥇 ani - 100
🥈 weird cat- 50
🥉 ) zelak - 40

#
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..

past pasture
languid meteor
#

rest normal

past pasture
#

Make a if condition

#

If (i < 3)

languid meteor
#

bro i think thats when there are less than 3 ppl

#

in lb

#

i said i want like this

past pasture
#

No it is not

languid meteor
#

gld medal ani - 150
Silver medl - 50
bronze medal - 10
4 -zelak- 5
5- 2

past pasture
#

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

languid meteor
#

so what do i do after i<3

#

do emotes?

#

coz i dont think

past pasture
#

You add the emote

languid meteor
#

i cn directly write

past pasture
#

Like do the if condition and in that if condition add the emote to content

languid meteor
#

and then dojs else { ${i+1}. ${user} - ${array[i].value} }

#

right?

past pasture
#

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

languid meteor
#

How?

past pasture
#
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

languid meteor
#

I'll try that tmrw
Gotta sleep now