Routes.guildMembers only returns 1 member

Running into a strange issue with discord.js REST where I am only getting a single result for Routes.guildMembers(guildId) despite the server I am testing clearly having over 5k members. Server Members Intent is enabled in discord dev portal.
let lastId = '0';
let lastId = '0';
// Fetch 1000 members at a time (Discord API limit)
const response = await rest.get(
Routes.guildMembers(guildId),
{ query: { limit: 1000, after: lastId } }
);

console.log(response); // for debugging....

// The response should be an array of member objects
const members = Array.isArray(response) ? response : [];

console.log({
message: 'Response from Discord API',
isArray: Array.isArray(response),
responseType: typeof response,
memberCount: members.length,
firstMember: members.length > 0 ? JSON.stringify(members[0]).substring(0, 100) + '...' : 'none'
});
// Fetch 1000 members at a time (Discord API limit)
const response = await rest.get(
Routes.guildMembers(guildId),
{ query: { limit: 1000, after: lastId } }
);

console.log(response); // for debugging....

// The response should be an array of member objects
const members = Array.isArray(response) ? response : [];

console.log({
message: 'Response from Discord API',
isArray: Array.isArray(response),
responseType: typeof response,
memberCount: members.length,
firstMember: members.length > 0 ? JSON.stringify(members[0]).substring(0, 100) + '...' : 'none'
});
when this runs the response returns an array with a single user in it.
[
{
avatar: null,
banner: null,
communication_disabled_until: null,
flags: <sanitized>,
joined_at: '<sanitized>',
nick: null,
pending: false,
premium_since: null,
roles: [ '<sanitized>' ],
unusual_dm_activity_until: null,
user: {
id: '<sanitized>',
username: '<sanitized>',
avatar: '<sanitized>',
discriminator: '0',
public_flags: <sanitized>,
flags: <sanitized>,
banner: null,
accent_color: null,
global_name: '<sanitized>',
avatar_decoration_data: null,
collectibles: null,
banner_color: null,
clan: null,
primary_guild: null
},
mute: false,
deaf: false
}
]
[
{
avatar: null,
banner: null,
communication_disabled_until: null,
flags: <sanitized>,
joined_at: '<sanitized>',
nick: null,
pending: false,
premium_since: null,
roles: [ '<sanitized>' ],
unusual_dm_activity_until: null,
user: {
id: '<sanitized>',
username: '<sanitized>',
avatar: '<sanitized>',
discriminator: '0',
public_flags: <sanitized>,
flags: <sanitized>,
banner: null,
accent_color: null,
global_name: '<sanitized>',
avatar_decoration_data: null,
collectibles: null,
banner_color: null,
clan: null,
primary_guild: null
},
mute: false,
deaf: false
}
]
If anyone has any insights into where I migth be going wrong here, please let me know.
14 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Em Gram
Em GramOP6mo ago
node -v v22.14.0 @discordjs/rest@2.5.1 discord-api-types@0.38.12
Inky
Inky6mo ago
Is the guild members intent enabled in the bot dev site?
Em Gram
Em GramOP6mo ago
yep, its a personal project so I onyl have one application for it just pulling data
Em Gram
Em GramOP6mo ago
No description
Em Gram
Em GramOP6mo ago
Im getting the feeling maybe i need to wait some time? I enabled the intent a while ago. booted the bot and rejoined the server and made a new secret key just to be sure.
Inky
Inky6mo ago
The guild id could be the wrong one tho
Em Gram
Em GramOP6mo ago
have confirmed guildid is correct only using 1 guild and its set in my .env plus the only user it returns is actually in the guild ohh good point let me make sure im doign that correctly bingo, thanks a heap, not a discord.js REST issue.... I just don't know how to structure a rest query properly :kekwcry: Fixed Query:
const params = new URLSearchParams({
limit: '1000',
after: lastId
});

// Fetch 1000 members at a time (Discord API limit)
const response = await rest.get(
`${Routes.guildMembers(guildId)}?${params.toString()}`
);
const params = new URLSearchParams({
limit: '1000',
after: lastId
});

// Fetch 1000 members at a time (Discord API limit)
const response = await rest.get(
`${Routes.guildMembers(guildId)}?${params.toString()}`
);
Inky
Inky6mo ago
{ query: params } prob would’ve been sufficient
Em Gram
Em GramOP6mo ago
ahh yep thats simpler
Inky
Inky6mo ago
You don’t want to just use the ws call to fetch all members? Or are you not using a websocket?
Em Gram
Em GramOP6mo ago
yer building in a cloudflare worker so no sockets
Inky
Inky6mo ago
Got it
Em Gram
Em GramOP6mo ago
appreciate the help

Did you find this page helpful?