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

162
Views
Unable to fetch all guild members through Discordjs v13

I have been trying to fetch the list of all members in my guild using the syntax as mentioned in the docs here. But am not receiving any output. Below is the code that I am using.

const { Client, Intents, Guild } = require("discord.js");
require("dotenv").config();
const commandHandler = require("./commands");
const fetch = require("node-fetch");

const client = new Client({
    intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_PRESENCES"],
});

client.once("ready", async (data) => {
    console.log("Ready!");
    console.log(`Logged in as ${client.user.tag}!`);
    const Guilds = client.guilds.cache.map((guild) => guild);
    console.log(Guilds[0]);
    await Guilds[0].members.fetch().then(console.log).catch(console.error);
});

client.on("interactionCreate", async (interaction) => {
    if (!interaction.isCommand()) return;

    if (interaction.commandName === "ping") {
        await interaction.reply(client.user + "๐Ÿ’–");
    }
});

client.on("messageCreate", commandHandler);
client.login(process.env.BOT_TOKEN); // Kushagra's bot

I am getting the information on Guild instance through the console.log on line 13. But do am not getting any output for line 15. However, I noticed that I was getting some output if I add options to fetch() command on line 14. I received some output when I added {query: 'random text'}.

Just wanted to understand why I am unable to get a list of all members. Thanks!๐Ÿ™‚

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

I found that I had missed out on the Intent. It seems that in order to fetch members you need to add an intent GUILD_MEMBERS while creating a client instance.

So replacing the client creation with the one below will work.

const client = new Client({ 
    intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_PRESENCES", "GUILD_MEMBERS"] 
});
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!