diff --git a/packages/discord.js/src/index.js b/packages/discord.js/src/index.js index cd86cfd0e991..cb2f7d722c5c 100644 --- a/packages/discord.js/src/index.js +++ b/packages/discord.js/src/index.js @@ -33,6 +33,7 @@ exports.Events = require('./util/Events'); exports.Formatters = require('./util/Formatters'); exports.GuildMemberFlagsBitField = require('./util/GuildMemberFlagsBitField').GuildMemberFlagsBitField; exports.IntentsBitField = require('./util/IntentsBitField'); +exports.InviteFlagsBitField = require('./util/InviteFlagsBitField.js').InviteFlagsBitField; exports.LimitedCollection = require('./util/LimitedCollection'); exports.MessageFlagsBitField = require('./util/MessageFlagsBitField'); exports.Options = require('./util/Options'); diff --git a/packages/discord.js/src/structures/Invite.js b/packages/discord.js/src/structures/Invite.js index 8d9b833dcf6d..954f047b1359 100644 --- a/packages/discord.js/src/structures/Invite.js +++ b/packages/discord.js/src/structures/Invite.js @@ -6,6 +6,7 @@ const { GuildScheduledEvent } = require('./GuildScheduledEvent'); const IntegrationApplication = require('./IntegrationApplication'); const InviteStageInstance = require('./InviteStageInstance'); const { DiscordjsError, ErrorCodes } = require('../errors'); +const { InviteFlagsBitField } = require('../util/InviteFlagsBitField.js'); /** * Represents an invitation to a guild channel. @@ -222,6 +223,17 @@ class Invite extends Base { } else { this.guildScheduledEvent ??= null; } + + if ('flags' in data) { + /** + * The flags of this invite. + * + * @type {Readonly} + */ + this.flags = new InviteFlagsBitField(data.flags).freeze(); + } else { + this.flags ??= new InviteFlagsBitField().freeze(); + } } /** diff --git a/packages/discord.js/src/util/APITypes.js b/packages/discord.js/src/util/APITypes.js index 70520cebc6a5..8ad10cc1f456 100644 --- a/packages/discord.js/src/util/APITypes.js +++ b/packages/discord.js/src/util/APITypes.js @@ -515,6 +515,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..87f4e7e74f05 --- /dev/null +++ b/packages/discord.js/src/util/InviteFlagsBitField.js @@ -0,0 +1,28 @@ +'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 966eb291e1a1..5f933203aeb0 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -215,6 +215,7 @@ import { APIFileComponent, APIMessageTopLevelComponent, EntryPointCommandHandlerType, + InviteFlags, } from 'discord-api-types/v10'; import { ChildProcess } from 'node:child_process'; import { EventEmitter } from 'node:events'; @@ -2274,6 +2275,7 @@ export class Invite extends Base { /** @deprecated Public Stage Instances don't exist anymore */ public stageInstance: InviteStageInstance | null; public guildScheduledEvent: GuildScheduledEvent | null; + public flags: Readonly; } /** @deprecated Public Stage Instances don't exist anymore */ @@ -2294,6 +2296,13 @@ export class InviteGuild extends AnonymousGuild { public welcomeScreen: WelcomeScreen | null; } +export type InviteFlagsString = keyof typeof InviteFlags; + +export class InviteFlagsBitField extends BitField { + public static Flags: typeof InviteFlags; + public static resolve(bit?: BitFieldResolvable): number; +} + export class LimitedCollection extends Collection { public constructor(options?: LimitedCollectionOptions, iterable?: Iterable); public maxSize: number;