diff --git a/src/structures/MessageAttachment.js b/src/structures/MessageAttachment.js index 4be74c8f44c7f..bf5f345ebbe6d 100644 --- a/src/structures/MessageAttachment.js +++ b/src/structures/MessageAttachment.js @@ -1,5 +1,6 @@ 'use strict'; +const AttachmentFlags = require('../util/AttachmentFlags'); const Util = require('../util/Util'); /** @@ -169,6 +170,16 @@ class MessageAttachment { } else { this.waveform ??= null; } + + if ('flags' in data) { + /** + * The flags of this attachment + * @type {Readonly} + */ + this.flags = new AttachmentFlags(data.flags).freeze(); + } else { + this.flags ??= new AttachmentFlags().freeze(); + } } /** diff --git a/src/structures/Role.js b/src/structures/Role.js index 76f02aca954e5..192724e12302a 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -5,6 +5,7 @@ const Base = require('./Base'); const { Error } = require('../errors'); const Permissions = require('../util/Permissions'); const SnowflakeUtil = require('../util/SnowflakeUtil'); +const RoleFlags = require('../util/RoleFlags'); let deprecationEmittedForComparePositions = false; @@ -142,6 +143,16 @@ class Role extends Base { this.tags.guildConnections = true; } } + + if ('flags' in data) { + /** + * The flags of this role + * @type {Readonly} + */ + this.flags = new RoleFlags(data.flags).freeze(); + } else { + this.flags ??= new RoleFlags().freeze(); + } } /** diff --git a/src/util/RoleFlags.js b/src/util/RoleFlags.js new file mode 100644 index 0000000000000..41e38ba3e8d3e --- /dev/null +++ b/src/util/RoleFlags.js @@ -0,0 +1,37 @@ +'use strict'; + +const BitField = require('./BitField'); + +/** + * Data structure that makes it easy to interact with an {@link GuildMember#flags} bitfield. + * @extends {BitField} + */ +class RoleFlags extends BitField {} + +/** + * @name RoleFlags + * @kind constructor + * @memberof RoleFlags + * @param {BitFieldResolvable} [bits=0] Bit(s) to read from + */ + +/** + * Numeric guild member flags. All available properties: + * * `IN_PROMPT` + * @type {Object} + * @see {@link https://discord.com/developers/docs/topics/permissions#role-object-role-flags} + */ +RoleFlags.FLAGS = { + IN_PROMPT: 1 << 0, +}; + +/** + * Data that can be resolved to give a role flag bitfield. This can be: + * * A string (see {@link RoleFlags.FLAGS}) + * * A role flag + * * An instance of RoleFlags + * * An Array of RoleFlagsResolvable + * @typedef {string|number|RoleFlags|RoleFlagsResolvable[]} RoleFlagsResolvable + */ + +module.exports = RoleFlags; diff --git a/typings/index.d.ts b/typings/index.d.ts index d12cade3193e3..39fc7eb859a9e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2158,6 +2158,7 @@ export class Role extends Base { /** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */ public deleted: boolean; public readonly editable: boolean; + public flags: Readonly; public guild: Guild; public readonly hexColor: HexColorString; public hoist: boolean; @@ -2193,6 +2194,14 @@ export class Role extends Base { public static comparePositions(role1: Role, role2: Role): number; } +export class RoleFlags extends BitField { + public static FLAGS: Record; + public static resolve(bit?: BitFieldResolvable): number; +} + +export type RoleFlagsString = + | 'IN_PROMPT'; + export class SelectMenuInteraction extends MessageComponentInteraction { public constructor(client: Client, data: RawMessageSelectMenuInteractionData); public readonly component: CacheTypeReducer<