Skip to content

Commit

Permalink
feat(Role): add flags (#9694)
Browse files Browse the repository at this point in the history
* feat(Role): add `flags`

* types: use RoleFlags enum

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

Co-authored-by: Jaw0r3k <jaworekwiadomosci@gmail.com>

---------

Co-authored-by: Jaw0r3k <jaworekwiadomosci@gmail.com>
  • Loading branch information
N1ckPro and jaw0r3k committed Aug 10, 2023
1 parent 692f0fc commit 3b18e5b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports.MessageFlagsBitField = require('./util/MessageFlagsBitField');
exports.Options = require('./util/Options');
exports.Partials = require('./util/Partials');
exports.PermissionsBitField = require('./util/PermissionsBitField');
exports.RoleFlagsBitField = require('./util/RoleFlagsBitField');
exports.ShardEvents = require('./util/ShardEvents');
exports.Status = require('./util/Status');
exports.SnowflakeUtil = require('@sapphire/snowflake').DiscordSnowflake;
Expand Down
11 changes: 11 additions & 0 deletions packages/discord.js/src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { PermissionFlagsBits } = require('discord-api-types/v10');
const Base = require('./Base');
const { DiscordjsError, ErrorCodes } = require('../errors');
const PermissionsBitField = require('../util/PermissionsBitField');
const RoleFlagsBitField = require('../util/RoleFlagsBitField');

/**
* Represents a role on Discord.
Expand Down Expand Up @@ -101,6 +102,16 @@ class Role extends Base {

if ('unicode_emoji' in data) this.unicodeEmoji = data.unicode_emoji;

if ('flags' in data) {
/**
* The flags of this role
* @type {Readonly<RoleFlagsBitField>}
*/
this.flags = new RoleFlagsBitField(data.flags).freeze();
} else {
this.flags ??= new RoleFlagsBitField().freeze();
}

/**
* The tags this role has
* @type {?Object}
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-payloads/common#PermissionFlagsBits}
*/

/**
* @external RoleFlags
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/RoleFlags}
*/

/**
* @external RESTGetAPIGuildThreadsResult
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#RESTGetAPIGuildThreadsResult}
Expand Down
26 changes: 26 additions & 0 deletions packages/discord.js/src/util/RoleFlagsBitField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const { RoleFlags } = require('discord-api-types/v10');
const BitField = require('./BitField');

/**
* Data structure that makes it easy to interact with a {@link Role#flags} bitfield.
* @extends {BitField}
*/
class RoleFlagsBitField extends BitField {
/**
* Numeric role flags.
* @type {RoleFlags}
* @memberof RoleFlagsBitField
*/
static Flags = RoleFlags;
}

/**
* @name RoleFlagsBitField
* @kind constructor
* @memberof RoleFlagsBitField
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
*/

module.exports = RoleFlagsBitField;
9 changes: 9 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ import {
APIGuildOnboardingPromptOption,
GuildOnboardingPromptType,
AttachmentFlags,
RoleFlags,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -2524,6 +2525,7 @@ export class Role extends Base {
public get createdAt(): Date;
public get createdTimestamp(): number;
public get editable(): boolean;
public flags: RoleFlagsBitField;
public guild: Guild;
public get hexColor(): HexColorString;
public hoist: boolean;
Expand Down Expand Up @@ -2559,6 +2561,13 @@ export class Role extends Base {
public toString(): RoleMention;
}

export type RoleFlagsString = keyof typeof RoleFlags;

export class RoleFlagsBitField extends BitField<RoleFlagsString> {
public static Flags: typeof RoleFlags;
public static resolve(bit?: BitFieldResolvable<RoleFlagsString, number>): number;
}

export class StringSelectMenuInteraction<
Cached extends CacheType = CacheType,
> extends MessageComponentInteraction<Cached> {
Expand Down

0 comments on commit 3b18e5b

Please sign in to comment.