Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Having problems with keyArray when update to discord.js v13

I'm codding a reset all member's ranking command using djs v13. I used the same code but with djs v12 and it worked properly. This is my code:

function resetrankingall() {
        let allmembers = message.guild.members.cache.keyArray();
        for (let i = 0; i < allmembers.length; i++) {
            let rankuser = message.guild.members.cache.get(allmembers[i]).user;
            const key = `${message.guild.id}-${rankuser.id}`;
            client.points.set(key, 1, `level`); //set level to 0
            client.points.set(key, 0, `points`); //set the points to 0
            client.points.set(key, 400, `neededpoints`) //set neededpoints to 0 for beeing sure
            client.points.set(key, "", `oldmessage`); //set old message to 0
        }
        const embed = new Discord.MessageEmbed()
        .setColor(embedcolor)
        .setDescription(`Successfully resetted everyone`)
        message.reply({ embeds: [embed] });

But when I update to djs v13 this err appears:

 let allmembers = message.guild.members.cache.keyArray()
                                                     ^
TypeError: message.guild.members.cache.keyArray is not a function

       

I made a little research on djs document and found this:

click to see image

So I tried to replace keyArray() with keys() and the err dissapeared but unfortuately the command does not worked either. My code after replacing:

function resetrankingall() {
        let allmembers = message.guild.members.cache.keys()
        for (let i = 0; i < allmembers.length; i++) {
            let rankuser =  message.guild.members.cache.get(allmembers[i]).user;
            const key = `${message.guild.id}-${rankuser.id}`;
            client.points.set(key, 1, `level`); //set level to 0
            client.points.set(key, 0, `points`); //set the points to 0
            client.points.set(key, 4000, `neededpoints`) //set neededpoints to 0 for beeing sure
            client.points.set(key, "", `oldmessage`); //set old message to 0
        }
        const embed = new MessageEmbed()
            .setColor(embedcolor)
            .setDescription(`Successfully resetted everyone`)
        message.reply({ embeds: [embed] });

The bot still reply with the embed when I run the command but it not work (the ranking of everbody still not reseted). Please help me, tysm!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have solve this trouble by replace some line of code:

async function resetrankingall() {
        const allGuildMembers = await message.guild.members.fetch();
        for (const guildMember of allGuildMembers.values()) {
            const key = `${message.guild.id}-${guildMember.user.id}`;
            client.points.set(key, 1, `level`); //set level to 0
            client.points.set(key, 0, `points`); //set the points to 0
            client.points.set(key, 4000, `neededpoints`) //set neededpoints to 0 for beeing sure
            client.points.set(key, "", `oldmessage`); //set old message to 0
        }
        const embed = new MessageEmbed()
            .setColor(embedcolor)
            .setDescription(`Successfully resetted everyone`)
        message.reply({ embeds: [embed] });

It works as expected. The problem may come from differences between djs v12 and v13. Thanks all for reading my question tho.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!