Skip to content

Commit

Permalink
feat(GuildAuditLogs): Support after (#9012)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite committed Jan 10, 2023
1 parent 6457519 commit f0d4264
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,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
Expand All @@ -791,18 +792,17 @@ 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);
}

Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5024,6 +5024,7 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo

export interface GuildAuditLogsFetchOptions<T extends GuildAuditLogsResolvable> {
before?: Snowflake | GuildAuditLogsEntry;
after?: Snowflake | GuildAuditLogsEntry;
limit?: number;
user?: UserResolvable;
type?: T;
Expand Down

0 comments on commit f0d4264

Please sign in to comment.