discordjs/discord.js · error · DiscordjsTypeError
InvalidType
InvalidType
Error message
InvalidType: user, UserResolvable
What it means
InvalidType ('user', 'UserResolvable') is thrown by Guild#fetchAuditLogs when the `user` argument cannot be resolved to a user id by client.users.resolveId(). fetchAuditLogs accepts a UserResolvable (User, GuildMember, snowflake, etc.); if the value is not one of these, resolveId returns null and this error is raised.
Source
Thrown at packages/discord.js/src/structures/Guild.js:878
* @param {GuildAuditLogsFetchOptions} [options={}] Options for fetching audit logs
* @returns {Promise<GuildAuditLogs>}
* @example
* // Output audit log entries
* guild.fetchAuditLogs()
* .then(audit => console.log(audit.entries.first()))
* .catch(console.error);
*/
async fetchAuditLogs({ before, after, limit, user, type } = {}) {
const query = makeURLSearchParams({
before: before?.id ?? before,
after: after?.id ?? after,
limit,
action_type: type,
});
if (user) {
const userId = this.client.users.resolveId(user);
if (!userId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable');
query.set('user_id', userId);
}
const data = await this.client.rest.get(Routes.guildAuditLog(this.id), { query });
return new GuildAuditLogs(this, data);
}
/**
* Fetches the guild onboarding data for this guild.
*
* @returns {Promise<GuildOnboarding>}
*/
async fetchOnboarding() {
const data = await this.client.rest.get(Routes.guildOnboarding(this.id));
return new GuildOnboarding(this.client, data);
}
/**View on GitHub (pinned to a81ed8a306)
Solutions
- Pass a valid UserResolvable: a User object, GuildMember, or a plain snowflake id string
- Resolve the stored value first: `const id = interaction.client.users.resolveId(raw); if (!id) return;` then pass the id
- If you only have a username/tag, search members via guild.members.fetch({ query, limit }) first and pass the resulting User
- Trim/validate snowflake strings: ensure /^[0-9]{17,20}$/.test(value) before passing
Example fix
// before
await guild.fetchAuditLogs({ user: 'someuser#1234' }); // not a UserResolvable
// after
const member = await guild.members.fetch({ query: 'someuser', limit: 1 });
await guild.fetchAuditLogs({ user: member.first() }); Defensive patterns
Strategy: validation
Validate before calling
const userId = interaction?.client?.users?.resolveId?.(user) ?? (typeof user === 'string' && /^\d{17,20}$/.test(user) ? user : null);
if (!userId) throw new TypeError('user must be a UserResolvable');
await guild.fetchAuditLogs({ user: userId }); Type guard
function isSnowflake(v) {
return typeof v === 'string' && /^\d{17,20}$/.test(v);
} Try / catch
try {
await guild.fetchAuditLogs({ user });
} catch (err) {
if (err.code === 'InvalidType') {
console.warn('user is not a UserResolvable:', user);
return;
}
throw err;
} Prevention
- Pass snowflake ids whenever you have them, instead of usernames/tags
- Validate ids with a snowflake regex before passing to the API
- Store User objects/ids in persistence layers, not display names
- Use client.users.resolveId() as a pre-check for early, clearer failures
When it happens
Trigger: Calling guild.fetchAuditLogs({ user: someObject }) where someObject is not a User/GuildMember/snowflake — e.g. passing a raw API user JSON, a username string like 'name#0001', an id string with whitespace, or an undefined variable coerced wrongly.
Common situations: Storing user references in a database and passing the stored string (a username/tag) back as `user`; passing the executor name parsed from an audit log text; passing objects from other libraries (selfbot/cache libs) that aren't discord.js UserResolvables; users deleting accounts so a cached member no longer resolves — note resolveId on a non-resolvable (not a deletion of a resolvable snowflake) is what throws here.
Related errors
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/b5ce4ff0756e37dc.
Report an issue: GitHub.