4

So I have this command that shows the riches users in a server this command worked yesterday however recently it has stopped working.

const { MessageEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");
const { prefix } = require("../../botconfig.json");
const db = require('quick.db')
let bal = require('../../database/balance');
let rep = require('../../database/rep');
let work = require('../../database/works');

module.exports = {
  config:{
    name: "rich",
    aliases: ["r"],
    category: "currency",
    description: "Tells who is rich",
    usage: ""
  },
run: async (client, message, args) => {
    // Get all members of the server before doing anything
    message.guild.members.fetch().then(guildMembers => {
        let board = [];

        for (let key of Object.keys(bal)) {
            // Checks if the collection of GuildMembers contains the key.
            if (guildMembers.has(key)) {
                let value = Object.assign({user: guildMembers.get(key).user}, bal[key]);
                board.push(value);
            }
        }
   const emojis = [':first_place:', ':second_place:', ':third_place:', ':small_blue_diamond:', ':small_blue_diamond:']
        board = board.sort((a,b) => b.balance-a.balance).splice(0, 5);
        let top = board.map((x, i) => `${emojis[i]} **${x.balance.toLocaleString()}** - ${x.user.tag}`).join('\n');
        let embed = new MessageEmbed() 
      
        .setColor("RANDOM") 
        .addField(`Richest users in **${message.guild.name}**`, `${top}`)
        .setFooter('Switch Version 1.1');
    

        return message.channel.send(embed);
    }).catch(console.error)
    }
}

The error code when the !rich command is used is as follows:

Guild_Members_Timeout: Members didn't arrive in time

I don't know if this is an issue within the bot or if it is an issue with discord.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Nicky
  • 261
  • 1
  • 5
  • 22

2 Answers2

11

Okay I have found the answer to my own problem it seems I needed to add intents to my discord bot to fetch the members.

All I did was add this line of code and it worked.

const intents = new Intents([
    Intents.NON_PRIVILEGED, // include all non-privileged intents, would be better to specify which ones you actually need
    "GUILD_MEMBERS", // lets you request guild members (i.e. fixes the issue)
]);
const client = new Client({ ws: { intents } });
Nicky
  • 261
  • 1
  • 5
  • 22
0

None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out? . In this post it is explained in great detail and that helped me out a lot.TLDR:go to discord developer portal on your particular application ,go to bot , on bot permissions tick whatever is needed and copy the number.Then use this number as a constructor parameter for new Discord.Intents('insert the number here').This worked for me.

GeorgeFkd
  • 49
  • 3