From 0076589ccc93e09d77a448874d1ceff5d0e91aa2 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 6 Jan 2023 11:46:20 +0000 Subject: [PATCH] feat(GuildAuditLogs): Support `after` (#9011) * feat(GuildAuditLogs): support `after` * refactor: remove variables They were only being used once each. Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/src/structures/Guild.js | 23 ++++++++++----------- packages/discord.js/typings/index.d.ts | 1 + 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/discord.js/src/structures/Guild.js b/packages/discord.js/src/structures/Guild.js index e0e5d1c6ddef..594163d94529 100644 --- a/packages/discord.js/src/structures/Guild.js +++ b/packages/discord.js/src/structures/Guild.js @@ -5,7 +5,6 @@ const { makeURLSearchParams } = require('@discordjs/rest'); const { ChannelType, GuildPremiumTier, Routes, GuildFeature } = require('discord-api-types/v10'); const AnonymousGuild = require('./AnonymousGuild'); const GuildAuditLogs = require('./GuildAuditLogs'); -const GuildAuditLogsEntry = require('./GuildAuditLogsEntry'); const GuildPreview = require('./GuildPreview'); const GuildTemplate = require('./GuildTemplate'); const Integration = require('./Integration'); @@ -700,7 +699,8 @@ class Guild extends AnonymousGuild { /** * Options used to fetch audit logs. * @typedef {Object} GuildAuditLogsFetchOptions - * @property {Snowflake|GuildAuditLogsEntry} [before] Only return entries before this entry + * @property {Snowflake|GuildAuditLogsEntry} [before] Consider only entries before this entry + * @property {Snowflake|GuildAuditLogsEntry} [after] Consider only entries after this entry * @property {number} [limit] The number of entries to return * @property {UserResolvable} [user] Only return entries for actions made by this user * @property {?AuditLogEvent} [type] Only return entries for this action type @@ -716,19 +716,18 @@ class Guild extends AnonymousGuild { * .then(audit => console.log(audit.entries.first())) * .catch(console.error); */ - async fetchAuditLogs(options = {}) { - if (options.before && options.before instanceof GuildAuditLogsEntry) options.before = options.before.id; - + async fetchAuditLogs({ before, after, limit, user, type } = {}) { const query = makeURLSearchParams({ - before: options.before, - limit: options.limit, - action_type: options.type, + before: before?.id ?? before, + after: after?.id ?? after, + limit, + action_type: type, }); - if (options.user) { - const id = this.client.users.resolveId(options.user); - if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable'); - query.set('user_id', id); + 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 }); diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 20c99a543f4a..15ab44e9b594 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -5322,6 +5322,7 @@ export interface GuildAuditLogsEntryTargetField { before?: Snowflake | GuildAuditLogsEntry; + after?: Snowflake | GuildAuditLogsEntry; limit?: number; user?: UserResolvable; type?: T;