{"record":{"id":"b5ce4ff0756e37dc","repo":"discordjs/discord.js","slug":"invalidtype-b5ce4f","errorCode":"InvalidType","errorMessage":"InvalidType: user, UserResolvable","messagePattern":"InvalidType: user, UserResolvable","errorType":"error_code","errorClass":"DiscordjsTypeError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/structures/Guild.js","lineNumber":878,"sourceCode":"   * @param {GuildAuditLogsFetchOptions} [options={}] Options for fetching audit logs\n   * @returns {Promise<GuildAuditLogs>}\n   * @example\n   * // Output audit log entries\n   * guild.fetchAuditLogs()\n   *   .then(audit => console.log(audit.entries.first()))\n   *   .catch(console.error);\n   */\n  async fetchAuditLogs({ before, after, limit, user, type } = {}) {\n    const query = makeURLSearchParams({\n      before: before?.id ?? before,\n      after: after?.id ?? after,\n      limit,\n      action_type: type,\n    });\n\n    if (user) {\n      const userId = this.client.users.resolveId(user);\n      if (!userId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable');\n      query.set('user_id', userId);\n    }\n\n    const data = await this.client.rest.get(Routes.guildAuditLog(this.id), { query });\n    return new GuildAuditLogs(this, data);\n  }\n\n  /**\n   * Fetches the guild onboarding data for this guild.\n   *\n   * @returns {Promise<GuildOnboarding>}\n   */\n  async fetchOnboarding() {\n    const data = await this.client.rest.get(Routes.guildOnboarding(this.id));\n    return new GuildOnboarding(this.client, data);\n  }\n\n  /**","sourceCodeStart":860,"sourceCodeEnd":896,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/structures/Guild.js#L860-L896","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait guild.fetchAuditLogs({ user: 'someuser#1234' }); // not a UserResolvable\n// after\nconst member = await guild.members.fetch({ query: 'someuser', limit: 1 });\nawait guild.fetchAuditLogs({ user: member.first() });","handlingStrategy":"validation","validationCode":"const userId = interaction?.client?.users?.resolveId?.(user) ?? (typeof user === 'string' && /^\\d{17,20}$/.test(user) ? user : null);\nif (!userId) throw new TypeError('user must be a UserResolvable');\nawait guild.fetchAuditLogs({ user: userId });","typeGuard":"function isSnowflake(v) {\n  return typeof v === 'string' && /^\\d{17,20}$/.test(v);\n}","tryCatchPattern":"try {\n  await guild.fetchAuditLogs({ user });\n} catch (err) {\n  if (err.code === 'InvalidType') {\n    console.warn('user is not a UserResolvable:', user);\n    return;\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["discord-js","audit-logs","invalid-argument-type","user-resolvable"],"backgroundTag":"invalid-resolvable-type","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}