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>
This commit is contained in:
Jiralite
2023-01-06 11:46:20 +00:00
committed by GitHub
parent 816aed478e
commit 0076589ccc
2 changed files with 12 additions and 12 deletions

View File

@@ -5,7 +5,6 @@ const { makeURLSearchParams } = require('@discordjs/rest');
const { ChannelType, GuildPremiumTier, Routes, GuildFeature } = require('discord-api-types/v10'); const { ChannelType, GuildPremiumTier, Routes, GuildFeature } = require('discord-api-types/v10');
const AnonymousGuild = require('./AnonymousGuild'); const AnonymousGuild = require('./AnonymousGuild');
const GuildAuditLogs = require('./GuildAuditLogs'); const GuildAuditLogs = require('./GuildAuditLogs');
const GuildAuditLogsEntry = require('./GuildAuditLogsEntry');
const GuildPreview = require('./GuildPreview'); const GuildPreview = require('./GuildPreview');
const GuildTemplate = require('./GuildTemplate'); const GuildTemplate = require('./GuildTemplate');
const Integration = require('./Integration'); const Integration = require('./Integration');
@@ -700,7 +699,8 @@ class Guild extends AnonymousGuild {
/** /**
* Options used to fetch audit logs. * Options used to fetch audit logs.
* @typedef {Object} GuildAuditLogsFetchOptions * @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 {number} [limit] The number of entries to return
* @property {UserResolvable} [user] Only return entries for actions made by this user * @property {UserResolvable} [user] Only return entries for actions made by this user
* @property {?AuditLogEvent} [type] Only return entries for this action type * @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())) * .then(audit => console.log(audit.entries.first()))
* .catch(console.error); * .catch(console.error);
*/ */
async fetchAuditLogs(options = {}) { async fetchAuditLogs({ before, after, limit, user, type } = {}) {
if (options.before && options.before instanceof GuildAuditLogsEntry) options.before = options.before.id;
const query = makeURLSearchParams({ const query = makeURLSearchParams({
before: options.before, before: before?.id ?? before,
limit: options.limit, after: after?.id ?? after,
action_type: options.type, limit,
action_type: type,
}); });
if (options.user) { if (user) {
const id = this.client.users.resolveId(options.user); const userId = this.client.users.resolveId(user);
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable'); if (!userId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable');
query.set('user_id', id); query.set('user_id', userId);
} }
const data = await this.client.rest.get(Routes.guildAuditLog(this.id), { query }); const data = await this.client.rest.get(Routes.guildAuditLog(this.id), { query });

View File

@@ -5322,6 +5322,7 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
export interface GuildAuditLogsFetchOptions<T extends GuildAuditLogsResolvable> { export interface GuildAuditLogsFetchOptions<T extends GuildAuditLogsResolvable> {
before?: Snowflake | GuildAuditLogsEntry; before?: Snowflake | GuildAuditLogsEntry;
after?: Snowflake | GuildAuditLogsEntry;
limit?: number; limit?: number;
user?: UserResolvable; user?: UserResolvable;
type?: T; type?: T;