mirror of
https://github.com/discordjs/discord.js.git
synced 2024-08-21 23:04:43 +12:00
feat(Role): add flags
(#9694)
* 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>
This commit is contained in:
parent
692f0fc96d
commit
3b18e5b08d
5 changed files with 52 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
26
packages/discord.js/src/util/RoleFlagsBitField.js
Normal file
26
packages/discord.js/src/util/RoleFlagsBitField.js
Normal file
|
@ -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
packages/discord.js/typings/index.d.ts
vendored
9
packages/discord.js/typings/index.d.ts
vendored
|
@ -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';
|
||||
|
@ -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;
|
||||
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue