Skip to content

Commit a222e53

Browse files
jaw0r3kN1ckPro
authored andcommitted
feat(Role): add flags (#9694)
Co-authored-by: n1ck_pro <59617443+N1ckPro@users.noreply.github.com>
1 parent d0fd79c commit a222e53

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

src/structures/MessageAttachment.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 AttachmentFlags = require('../util/AttachmentFlags');
34
const Util = require('../util/Util');
45

56
/**
@@ -169,6 +170,16 @@ class MessageAttachment {
169170
} else {
170171
this.waveform ??= null;
171172
}
173+
174+
if ('flags' in data) {
175+
/**
176+
* The flags of this attachment
177+
* @type {Readonly<AttachmentFlags>}
178+
*/
179+
this.flags = new AttachmentFlags(data.flags).freeze();
180+
} else {
181+
this.flags ??= new AttachmentFlags().freeze();
182+
}
172183
}
173184

174185
/**

src/structures/Role.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const Base = require('./Base');
55
const { Error } = require('../errors');
66
const Permissions = require('../util/Permissions');
77
const SnowflakeUtil = require('../util/SnowflakeUtil');
8+
const RoleFlags = require('../util/RoleFlags');
89

910
let deprecationEmittedForComparePositions = false;
1011

@@ -142,6 +143,16 @@ class Role extends Base {
142143
this.tags.guildConnections = true;
143144
}
144145
}
146+
147+
if ('flags' in data) {
148+
/**
149+
* The flags of this role
150+
* @type {Readonly<RoleFlags>}
151+
*/
152+
this.flags = new RoleFlags(data.flags).freeze();
153+
} else {
154+
this.flags ??= new RoleFlags().freeze();
155+
}
145156
}
146157

147158
/**

src/util/RoleFlags.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
const BitField = require('./BitField');
4+
5+
/**
6+
* Data structure that makes it easy to interact with an {@link GuildMember#flags} bitfield.
7+
* @extends {BitField}
8+
*/
9+
class RoleFlags extends BitField {}
10+
11+
/**
12+
* @name RoleFlags
13+
* @kind constructor
14+
* @memberof RoleFlags
15+
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
16+
*/
17+
18+
/**
19+
* Numeric guild member flags. All available properties:
20+
* * `IN_PROMPT`
21+
* @type {Object}
22+
* @see {@link https://discord.com/developers/docs/topics/permissions#role-object-role-flags}
23+
*/
24+
RoleFlags.FLAGS = {
25+
IN_PROMPT: 1 << 0,
26+
};
27+
28+
/**
29+
* Data that can be resolved to give a role flag bitfield. This can be:
30+
* * A string (see {@link RoleFlags.FLAGS})
31+
* * A role flag
32+
* * An instance of RoleFlags
33+
* * An Array of RoleFlagsResolvable
34+
* @typedef {string|number|RoleFlags|RoleFlagsResolvable[]} RoleFlagsResolvable
35+
*/
36+
37+
module.exports = RoleFlags;

typings/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,6 +2159,7 @@ export class Role extends Base {
21592159
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
21602160
public deleted: boolean;
21612161
public readonly editable: boolean;
2162+
public flags: Readonly<RoleFlags>;
21622163
public guild: Guild;
21632164
public readonly hexColor: HexColorString;
21642165
public hoist: boolean;
@@ -2194,6 +2195,14 @@ export class Role extends Base {
21942195
public static comparePositions(role1: Role, role2: Role): number;
21952196
}
21962197

2198+
export class RoleFlags extends BitField<RoleFlagsString> {
2199+
public static FLAGS: Record<RoleFlagsString, number>;
2200+
public static resolve(bit?: BitFieldResolvable<RoleFlagsString, number>): number;
2201+
}
2202+
2203+
export type RoleFlagsString =
2204+
| 'IN_PROMPT';
2205+
21972206
export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
21982207
public constructor(client: Client, data: RawMessageSelectMenuInteractionData);
21992208
public readonly component: CacheTypeReducer<

0 commit comments

Comments
 (0)