diff --git a/packages/discord.js/src/structures/GuildAuditLogsEntry.js b/packages/discord.js/src/structures/GuildAuditLogsEntry.js index 53c5b3d3fcd3..2d6430b42659 100644 --- a/packages/discord.js/src/structures/GuildAuditLogsEntry.js +++ b/packages/discord.js/src/structures/GuildAuditLogsEntry.js @@ -14,7 +14,6 @@ const Partials = require('../util/Partials'); const { flatten } = require('../util/Util'); const Targets = { - All: 'All', Guild: 'Guild', GuildScheduledEvent: 'GuildScheduledEvent', Channel: 'Channel', @@ -503,6 +502,15 @@ class GuildAuditLogsEntry { return new Date(this.createdTimestamp); } + /** + * Checks whether this GuildAuditLogsEntry is of the specified {@link AuditLogEvent} type. + * @param {AuditLogEvent} action The type to check for + * @returns {boolean} + */ + isAction(action) { + return this.action === action; + } + toJSON() { return flatten(this, { createdTimestamp: true }); } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index dc2aac43f714..8d30577c7262 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1467,9 +1467,9 @@ export class Guild extends AnonymousGuild { public editOnboarding(options: GuildOnboardingEditOptions): Promise; public editWelcomeScreen(options: WelcomeScreenEditOptions): Promise; public equals(guild: Guild): boolean; - public fetchAuditLogs( + public fetchAuditLogs( options?: GuildAuditLogsFetchOptions, - ): Promise>; + ): Promise>; public fetchIntegrations(): Promise>; public fetchOnboarding(): Promise; public fetchOwner(options?: BaseFetchOptions): Promise; @@ -1515,7 +1515,7 @@ export class Guild extends AnonymousGuild { public toJSON(): unknown; } -export class GuildAuditLogs { +export class GuildAuditLogs { private constructor(guild: Guild, data: RawGuildAuditLogData); private applicationCommands: Collection; private webhooks: Collection>; @@ -1527,36 +1527,40 @@ export class GuildAuditLogs { private constructor(guild: Guild, data: RawGuildAuditLogEntryData, logs?: GuildAuditLogs); public static Targets: GuildAuditLogsTargets; - public action: TResolvedType; + public action: TAction; public actionType: TActionType; public changes: AuditLogChange[]; public get createdAt(): Date; public get createdTimestamp(): number; public executorId: Snowflake | null; public executor: User | null; - public extra: TResolvedType extends keyof GuildAuditLogsEntryExtraField - ? GuildAuditLogsEntryExtraField[TResolvedType] - : null; + public extra: TAction extends keyof GuildAuditLogsEntryExtraField ? GuildAuditLogsEntryExtraField[TAction] : null; public id: Snowflake; public reason: string | null; public targetId: Snowflake | null; - public target: TTargetType extends keyof GuildAuditLogsEntryTargetField - ? GuildAuditLogsEntryTargetField[TTargetType] + public target: TTargetType extends keyof GuildAuditLogsEntryTargetField + ? GuildAuditLogsEntryTargetField[TTargetType] : Role | GuildEmoji | { id: Snowflake } | null; public targetType: TTargetType; public static actionType(action: AuditLogEvent): GuildAuditLogsActionType; public static targetType(target: AuditLogEvent): GuildAuditLogsTargetType; + public isAction( + action: TCheckAction, + ): this is GuildAuditLogsEntry< + TCheckAction, + TCheckAction extends keyof GuildAuditLogsTypes ? GuildAuditLogsTypes[TCheckAction][1] : 'All', + TCheckAction extends keyof GuildAuditLogsTypes ? GuildAuditLogsTypes[TCheckAction][0] : 'Unknown' + >; public toJSON(): unknown; } @@ -5726,12 +5730,14 @@ export interface GuildAuditLogsEntryExtraField { }; } -export interface GuildAuditLogsEntryTargetField { +export interface GuildAuditLogsEntryTargetField { User: User | null; Guild: Guild; Webhook: Webhook; Invite: Invite; - Message: TActionType extends AuditLogEvent.MessageBulkDelete ? Guild | { id: Snowflake } : User; + Emoji: GuildEmoji; + Role: Role; + Message: TAction extends AuditLogEvent.MessageBulkDelete ? Guild | { id: Snowflake } : User; Integration: Integration; Channel: NonThreadGuildBasedChannel | { id: Snowflake; [x: string]: unknown }; Thread: AnyThreadChannel | { id: Snowflake; [x: string]: unknown }; @@ -5753,7 +5759,7 @@ export interface GuildAuditLogsFetchOptions>>( guild.fetchAuditLogs({ type: AuditLogEvent.IntegrationUpdate }), ); -expectType>>(guild.fetchAuditLogs({ type: null })); +expectType>>(guild.fetchAuditLogs({ type: null })); expectType>>(guild.fetchAuditLogs()); expectType | undefined>>( @@ -2144,10 +2144,10 @@ expectAssignable al.entries.first()), ); -expectType | undefined>>( +expectType | undefined>>( guild.fetchAuditLogs({ type: null }).then(al => al.entries.first()), ); -expectType | undefined>>( +expectType | undefined>>( guild.fetchAuditLogs().then(al => al.entries.first()), );