Skip to content

Commit 73c72ea

Browse files
committed
feat(Attachment): add flags
1 parent 75d91b5 commit 73c72ea

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

packages/discord.js/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exports.DiscordjsErrorCodes = require('./errors/ErrorCodes');
1919
// Utilities
2020
exports.ActivityFlagsBitField = require('./util/ActivityFlagsBitField');
2121
exports.ApplicationFlagsBitField = require('./util/ApplicationFlagsBitField');
22+
exports.AttachmentFlagsBitField = require('./util/AttachmentFlagsBitField');
2223
exports.BaseManager = require('./managers/BaseManager');
2324
exports.BitField = require('./util/BitField');
2425
exports.ChannelFlagsBitField = require('./util/ChannelFlagsBitField');

packages/discord.js/src/structures/Attachment.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const AttachmentFlagsBitField = require('../util/AttachmentFlagsBitField.js');
34
const { basename, flatten } = require('../util/Util');
45

56
/**
@@ -121,6 +122,16 @@ class Attachment {
121122
} else {
122123
this.waveform ??= null;
123124
}
125+
126+
if ('flags' in data) {
127+
/**
128+
* The flags of this attachment
129+
* @type {Readonly<AttachmentFlagsBitField>}
130+
*/
131+
this.flags = new AttachmentFlagsBitField(data.flags).freeze();
132+
} else {
133+
this.flags ??= new AttachmentFlagsBitField().freeze();
134+
}
124135
}
125136

126137
/**

packages/discord.js/src/util/APITypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@
210210
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/ApplicationRoleConnectionMetadataType}
211211
*/
212212

213+
/**
214+
* @external AttachmentFlags
215+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/AttachmentFlags}
216+
*/
217+
213218
/**
214219
* @external AutoModerationActionType
215220
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/AutoModerationActionType}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const { AttachmentFlags } = require('discord-api-types/v10');
4+
const BitField = require('./BitField');
5+
6+
/**
7+
* Data structure that makes it easy to interact with an {@link Attachment#flags} bitfield.
8+
* @extends {BitField}
9+
*/
10+
class AttachmentFlagsBitField extends BitField {
11+
/**
12+
* Numeric attachment flags.
13+
* @type {AttachmentFlags}
14+
* @memberof AttachmentFlagsBitField
15+
*/
16+
static Flags = AttachmentFlags;
17+
}
18+
19+
/**
20+
* @name AttachmentFlagsBitField
21+
* @kind constructor
22+
* @memberof AttachmentFlagsBitField
23+
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
24+
*/
25+
26+
module.exports = AttachmentFlagsBitField;

packages/discord.js/typings/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,7 @@ export class Attachment {
20252025
public description: string | null;
20262026
public duration: number | null;
20272027
public ephemeral: boolean;
2028+
public flags: AttachmentFlagsBitField;
20282029
public height: number | null;
20292030
public id: Snowflake;
20302031
public name: string;
@@ -2037,6 +2038,14 @@ export class Attachment {
20372038
public toJSON(): unknown;
20382039
}
20392040

2041+
export type AttachmentFlagsString = any;
2042+
// export type AttachmentFlagsString = keyof typeof AttachmentFlags;
2043+
2044+
export class AttachmentFlagsBitField extends BitField<AttachmentFlagsString> {
2045+
public static FLAGS: Record<AttachmentFlagsString, number>;
2046+
public static resolve(bit?: BitFieldResolvable<AttachmentFlagsString, number>): number;
2047+
}
2048+
20402049
export class MessageCollector extends Collector<Snowflake, Message, [Collection<Snowflake, Message>]> {
20412050
public constructor(channel: TextBasedChannel, options?: MessageCollectorOptions);
20422051
private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;

0 commit comments

Comments
 (0)