Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda