Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ class GuildAuditLogsEntry {
* @type {AuditLogChange[]}
*/
this.changes =
data.changes?.map(change => ({ key: change.key, old: change.old_value, new: change.new_value })) ?? [];
data.changes?.map(change => ({
key: change.key,
...('old_value' in change ? { old: change.old_value } : {}),
...('new_value' in change ? { new: change.new_value } : {}),
})) ?? [];

/**
* The entry's id
Expand Down
12 changes: 7 additions & 5 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4991,11 +4991,13 @@ export interface ApplicationRoleConnectionMetadataEditOptions {
type: ApplicationRoleConnectionMetadataType;
}

export interface AuditLogChange {
key: APIAuditLogChange['key'];
old?: APIAuditLogChange['old_value'];
new?: APIAuditLogChange['new_value'];
}
export type AuditLogChange = {
[SourceElement in APIAuditLogChange as SourceElement['key']]: {
key: SourceElement['key'];
old?: SourceElement['old_value'];
new?: SourceElement['new_value'];
};
}[APIAuditLogChange['key']];

export interface AutoModerationAction {
type: AutoModerationActionType;
Expand Down
11 changes: 11 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import {
Collector,
GuildAuditLogsEntry,
GuildAuditLogs,
type AuditLogChange,
StageInstance,
ActionRowBuilder,
ButtonComponent,
Expand Down Expand Up @@ -2171,6 +2172,16 @@ expectType<Promise<User | undefined>>(
guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete }).then(al => al.entries.first()?.target),
);

declare const AuditLogChange: AuditLogChange;
// @ts-expect-error
expectType<boolean | undefined>(AuditLogChange.old);
// @ts-expect-error
expectType<boolean | undefined>(AuditLogChange.new);
if (AuditLogChange.key === 'available') {
expectType<boolean | undefined>(AuditLogChange.old);
expectType<boolean | undefined>(AuditLogChange.new);
}

declare const TextBasedChannel: TextBasedChannel;
declare const TextBasedChannelTypes: TextBasedChannelTypes;
declare const VoiceBasedChannel: VoiceBasedChannel;
Expand Down