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:

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