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

65
Views
How do I cache all the members in the server when starting the bot using discordjs?

I currently need to ping the person first then it will cache into the bot. After that, I would then be able to use their ID.

How do I make it so I can use their ID straight away?

This is my avatar command. How would I go to improve and add that command?

module.exports = {
    config,
    run: async (client, message, args) => {
        let embed = new Discord.MessageEmbed();
        let mention = message.mentions.members.first()
        if(!mention && !isNaN(args[0]) && args[0]) try {mention = await client.users.fetch(args[0])} catch (err) {}
        if(!mention && args[0] && isNaN(args[0])) try {mention = await message.guild.members.fetch({query: args[0], limit: 1})} catch (err) {}
        if(!mention) mention = message.author
        if(mention.roles) mention = mention.user
        let user = message.mentions.users.first()
          || message.guild.members.cache.get(args[0])?.user
          || message.author;
            embed.setTitle('Avatar!');
            embed.setAuthor(message.author.tag, message.author.displayAvatarURL());
            embed.setColor(client.config.colors.info);
            embed.setImage(user.displayAvatarURL({dynamic: true}));
            return message.reply({embeds: [embed] });
        }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't have to.

All members will be cached when your bot starts up (remember to put const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); in your file!)

See the first code block here (under implementation).

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!