discordjs/discord.js · error · Error
Request timed out
Error message
Request timed out
What it means
This error is thrown by the gateway REQUEST_GUILD_MEMBERS flow when the library's timeout elapses before enough guild member chunk responses arrive. The library sends a Gateway Request Members command and awaits chunk dispatches; if the gateway does not reply (or not fully) within the timeout, the AbortController fires, the iterator sees an AbortError, and it rethrows a generic 'Request timed out' error. It means the operation was abandoned client-side, not that Discord rejected the request.
Source
Thrown at packages/core/src/client.ts:304
nonce,
notFound: data.not_found ?? null,
presences: data.presences ?? null,
chunkIndex: data.chunk_index,
chunkCount: data.chunk_count,
};
if (data.chunk_index >= data.chunk_count - 1) break;
// eslint-disable-next-line require-atomic-updates
timer = createTimer(controller, timeout);
}
} catch (error) {
if (error instanceof Error && error.name === 'AbortError') {
if (error.cause instanceof GatewayRateLimitError) {
throw error.cause;
}
throw new Error('Request timed out');
}
throw error;
} finally {
cleanup();
}
}
/**
* Requests guild members from the gateway.
*
* @see {@link https://discord.com/developers/docs/topics/gateway-events#request-guild-members}
* @param options - The options for the request
* @param timeout - The timeout for waiting for each guild members chunk event
* @example
* Requesting specific members from a guild
* ```ts
* const { members } = await client.requestGuildMembers({ guild_id: '1234567890', user_ids: ['9876543210'] });View on GitHub (pinned to a81ed8a306)
Solutions
- Check gateway connectivity (shard Events) and ensure the client is fully ready (READY/GUILD_CREATE) before calling requestGuildMembers.
- Increase the timeout passed to requestGuildMembers and consume the full iterator instead of breaking early.
- Verify the guild id is correct and the bot is a member of that guild on the connected shard.
- Retry the request only after confirming the shard is not reconnecting; requests during RESUME are unreliable.
- Narrow the request (userIds, or query+limit) so fewer chunks are needed before the timeout.
Example fix
// before
const members = await client.guilds.cache.get(id).members.fetch({ query: '' });
// after
const guild = client.guilds.cache.get(id);
if (!guild) throw new Error('Bot is not in guild');
const members = await guild.members.fetch({ query: '', time: 120_000 }); // longer timeout Defensive patterns
Strategy: try-catch
Validate before calling
if (!client.isReady()) throw new Error('Client not ready');
const guild = client.guilds.cache.get(guildId);
if (!guild) throw new Error(`Bot not in guild ${guildId}`); Type guard
function isKnownGuild(client, id) {
return typeof id === 'string' && /^\d{17,20}$/.test(id) && client.guilds.cache.has(id);
} Try / catch
try {
await client.requestGuildMembers({ guild: guildId, query: '', limit: 0 });
} catch (err) {
if (err.message === 'Request timed out') {
// shard degraded: schedule retry after checking shard status
return retryLater(guildId);
}
throw err;
} Prevention
- Wait for client ready and stable shards before requesting members.
- Use longer/custom timeouts for large guilds.
- Narrow requests with userIds or limit+query to reduce chunk count.
- Monitor shard reconnect events and defer member requests until resume completes.
- Prefer guild.members.fetch on guilds already fully cached.
When it happens
Trigger: Calling requestGuildMembers when the gateway connection is degraded or reconnecting, when the request targets a guild the bot is not in on that shard, when fetching all members of a very large guild and not all chunks arrive before the timeout, or when awaiting presences that were never requested.
Common situations: Bots doing member caching on startup across many large guilds; network hiccups or gateway RESUME/RESUMING mid-request; accidentally requesting a guild the shard is not subscribed to; overly short timeout configured in the call.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- InteractionAlreadyReplied
- InteractionNotReplied
- HTTPError(status, res.statusText, method, url, requestData)
- Not enough sessions remaining to spawn ${shardIds.length} sh
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/5cce6256981f50eb.
Report an issue: GitHub.