Skip to content

Commit 692f0fc

Browse files
almeidxJiralitekodiakhq[bot]
authored
feat(Attachment): add flags (#9686)
* feat(Attachment): add `flags` * fix: import * fix: flags casing Co-authored-by: Jiralite <[email protected]> --------- Co-authored-by: Jiralite <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 0de071d commit 692f0fc

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
@@ -166,6 +166,7 @@ import {
166166
APIGuildOnboardingPrompt,
167167
APIGuildOnboardingPromptOption,
168168
GuildOnboardingPromptType,
169+
AttachmentFlags,
169170
} from 'discord-api-types/v10';
170171
import { ChildProcess } from 'node:child_process';
171172
import { EventEmitter } from 'node:events';
@@ -2070,6 +2071,7 @@ export class Attachment {
20702071
public description: string | null;
20712072
public duration: number | null;
20722073
public ephemeral: boolean;
2074+
public flags: AttachmentFlagsBitField;
20732075
public height: number | null;
20742076
public id: Snowflake;
20752077
public name: string;
@@ -2082,6 +2084,13 @@ export class Attachment {
20822084
public toJSON(): unknown;
20832085
}
20842086

2087+
export type AttachmentFlagsString = keyof typeof AttachmentFlags;
2088+
2089+
export class AttachmentFlagsBitField extends BitField<AttachmentFlagsString> {
2090+
public static Flags: Record<AttachmentFlagsString, number>;
2091+
public static resolve(bit?: BitFieldResolvable<AttachmentFlagsString, number>): number;
2092+
}
2093+
20852094
export class MessageCollector extends Collector<Snowflake, Message, [Collection<Snowflake, Message>]> {
20862095
public constructor(channel: TextBasedChannel, options?: MessageCollectorOptions);
20872096
private _handleChannelDeletion(channel: NonThreadGuildBasedChannel): void;

0 commit comments

Comments
 (0)