From aa04fd73119b571d17671d8e8fdfa42ada80f754 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Fri, 6 Jan 2023 18:14:41 +0700 Subject: [PATCH] feat(GuildAuditLogs): Support `after` #9012 djs --- src/structures/Guild.js | 21 ++++++++------------- typings/index.d.ts | 1 + 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index bab9c96..79dbda8 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -782,7 +782,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 {AuditLogAction|number} [type] Only return entries for this action type @@ -798,20 +799,14 @@ class Guild extends AnonymousGuild { * .then(audit => console.log(audit.entries.first())) * .catch(console.error); */ - async fetchAuditLogs(options = {}) { - if (options.before && options.before instanceof GuildAuditLogs.Entry) { - options.before = options.before.id; - } - if (typeof options.type === 'string') { - options.type = GuildAuditLogs.Actions[options.type]; - } - + async fetchAuditLogs({ before, after, limit, user, type } = {}) { const data = await this.client.api.guilds(this.id)['audit-logs'].get({ query: { - before: options.before, - limit: options.limit, - user_id: this.client.users.resolveId(options.user), - action_type: options.type, + before: before?.id ?? before, + after: after?.id ?? after, + limit, + user_id: this.client.users.resolveId(user), + action_type: typeof type === 'string' ? GuildAuditLogs.Actions[type] : type, }, }); return GuildAuditLogs.build(this, data); diff --git a/typings/index.d.ts b/typings/index.d.ts index 4eefe15..a9fdfc0 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -5907,6 +5907,7 @@ export interface GuildAuditLogsEntryTargetField { before?: Snowflake | GuildAuditLogsEntry; + after?: Snowflake | GuildAuditLogsEntry; limit?: number; user?: UserResolvable; type?: T;