0

Im trying to make a leaderboard command, i figured out how to do it for all of my bots users, but i cant figure out how to do it for just one guild i keep getting this error: TypeError: message.guild.members.forEach is not a function

Code:

const db = require('quick.db')
const ms = require('parse-ms')
const Discord = require(`discord.js`);
module.exports = {
    name: 'lb',
    execute(message) {
    const client = message.client
let prefix = db.get(`prefix_${message.guild.id}`)
let defaultprefix = "$$"
if(prefix === null) prefix = defaultprefix
let money = message.guild.members.forEach(member => db.get(`money_${member.id}`)).sort((a, b) => b.data - a.data)
money.length = 15;
var finalLb = ``;
for (var i in money) {
finalLb += `**#${money.indexOf(money[i])+1}** ${client.users.cache.get(money[i].ID.split('_')[1]) ? client.users.cache.get(money[i].ID.split('_')[1]).tag : `Deleted User#0000`} - ${money[i].data}\n`;
}

      const embed = new Discord.MessageEmbed()
      .setAuthor(`Top 15 richest users in this server`)
      .setDescription(finalLb)
      .setThumbnail(message.guild.iconURL({ dynamic: true }))
      .setColor(`990000`)      
      .setTimestamp()
  
      message.channel.send(embed);
    }
}```
ronan
  • 11
  • 2
  • 1
    If you're using discord.js v12.x, you need to pass it through the cache property. `message.guild.members.cache.forEach()` – Lioness100 Oct 22 '20 at 13:58

1 Answers1

1

The property .members of a Guild refers to the GuildMemberManager. To get the actual collection of members, you need to get the GuildMemberManager.cache property.

Change your code to the following and give it a try:

let money = message.guild.members.cache.forEach(<Code here>);
T. Dirks
  • 3,566
  • 1
  • 19
  • 34
  • Please mark this answer as accepted if it fixed your problem. This way it'll help others find the solution quicker if they have a similar problem – T. Dirks Oct 23 '20 at 06:21