diff --git a/packages/discord.js/src/index.js b/packages/discord.js/src/index.js index 53af1b0fd759..d05fa7b45225 100644 --- a/packages/discord.js/src/index.js +++ b/packages/discord.js/src/index.js @@ -29,6 +29,7 @@ exports.Constants = require('./util/Constants.js'); exports.Events = require('./util/Events.js').Events; exports.GuildMemberFlagsBitField = require('./util/GuildMemberFlagsBitField.js').GuildMemberFlagsBitField; exports.IntentsBitField = require('./util/IntentsBitField.js').IntentsBitField; +exports.InviteFlagsBitField = require('./util/InviteFlagsBitField.js').InviteFlagsBitField; exports.LimitedCollection = require('./util/LimitedCollection.js').LimitedCollection; exports.MessageFlagsBitField = require('./util/MessageFlagsBitField.js').MessageFlagsBitField; exports.Options = require('./util/Options.js').Options; diff --git a/packages/discord.js/src/structures/GuildInvite.js b/packages/discord.js/src/structures/GuildInvite.js index 33e94a42e3ff..2ac2c2cbb29a 100644 --- a/packages/discord.js/src/structures/GuildInvite.js +++ b/packages/discord.js/src/structures/GuildInvite.js @@ -2,6 +2,7 @@ const { Routes, PermissionFlagsBits, InviteType } = require('discord-api-types/v10'); const { DiscordjsError, ErrorCodes } = require('../errors/index.js'); +const { InviteFlagsBitField } = require('../util/InviteFlagsBitField.js'); const { BaseInvite } = require('./BaseInvite.js'); const { GuildScheduledEvent } = require('./GuildScheduledEvent.js'); const { IntegrationApplication } = require('./IntegrationApplication.js'); @@ -48,6 +49,17 @@ class GuildInvite extends BaseInvite { _patch(data) { super._patch(data); + if ('flags' in data) { + /** + * The flags of this invite. + * + * @type {Readonly} + */ + this.flags = new InviteFlagsBitField(data.flags).freeze(); + } else { + this.flags ??= new InviteFlagsBitField().freeze(); + } + if ('guild' in data) { /** * The guild the invite is for. May include welcome screen data. diff --git a/packages/discord.js/src/util/APITypes.js b/packages/discord.js/src/util/APITypes.js index 92377d3d550f..0da8d2ed55dd 100644 --- a/packages/discord.js/src/util/APITypes.js +++ b/packages/discord.js/src/util/APITypes.js @@ -514,6 +514,11 @@ * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/InteractionResponseType} */ +/** + * @external InviteFlags + * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/InviteFlags} + */ + /** * @external InviteType * @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/InviteType} diff --git a/packages/discord.js/src/util/InviteFlagsBitField.js b/packages/discord.js/src/util/InviteFlagsBitField.js new file mode 100644 index 000000000000..da5fe205c771 --- /dev/null +++ b/packages/discord.js/src/util/InviteFlagsBitField.js @@ -0,0 +1,29 @@ +/* eslint-disable jsdoc/check-values */ +'use strict'; + +const { InviteFlags } = require('discord-api-types/v10'); +const { BitField } = require('./BitField.js'); + +/** + * Data structure that makes it easy to interact with a {@link GuildInvite#flags} bit field. + * + * @extends {BitField} + */ +class InviteFlagsBitField extends BitField { + /** + * Numeric invite flags. + * + * @type {InviteFlags} + * @memberof InviteFlagsBitField + */ + static Flags = InviteFlags; +} + +/** + * @name InviteFlagsBitField + * @kind constructor + * @memberof InviteFlagsBitField + * @param {BitFieldResolvable} [bits=0] Bit(s) to read from + */ + +exports.InviteFlagsBitField = InviteFlagsBitField; diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index fe6b6b50c0eb..7e8554823383 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -159,6 +159,7 @@ import { InteractionContextType, InteractionResponseType, InteractionType, + InviteFlags, InviteTargetType, InviteType, Locale, @@ -2039,6 +2040,7 @@ export class BaseInvite extends Base { export class GuildInvite extends BaseInvite { public readonly type: InviteType.Guild; + public flags: Readonly; public guild: Guild | InviteGuild | null; public readonly guildId: Snowflake; public channel: NonThreadGuildBasedChannel | null; @@ -2054,6 +2056,13 @@ export class GuildInvite extends BaseInvit public delete(reason?: string): Promise; } +export type InviteFlagsString = keyof typeof InviteFlags; + +export class InviteFlagsBitField extends BitField { + public static Flags: typeof InviteFlags; + public static resolve(bit?: BitFieldResolvable): number; +} + export class GroupDMInvite extends BaseInvite { public readonly type: InviteType.GroupDM; public channel: PartialGroupDMChannel | null;