Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions packages/discord.js/src/structures/GuildInvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -48,6 +49,17 @@ class GuildInvite extends BaseInvite {
_patch(data) {
super._patch(data);

if ('flags' in data) {
/**
* The flags of this invite.
*
* @type {Readonly<InviteFlagsBitField>}
*/
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.
Expand Down
29 changes: 29 additions & 0 deletions packages/discord.js/src/util/InviteFlagsBitField.js
Original file line number Diff line number Diff line change
@@ -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 an {@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;
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 @@ -159,6 +159,7 @@ import {
InteractionContextType,
InteractionResponseType,
InteractionType,
InviteFlags,
InviteTargetType,
InviteType,
Locale,
Expand Down Expand Up @@ -2039,6 +2040,7 @@ export class BaseInvite<WithCounts extends boolean = boolean> extends Base {

export class GuildInvite<WithCounts extends boolean = boolean> extends BaseInvite<WithCounts> {
public readonly type: InviteType.Guild;
public flags: Readonly<InviteFlagsBitField>;
public guild: Guild | InviteGuild | null;
public readonly guildId: Snowflake;
public channel: NonThreadGuildBasedChannel | null;
Expand All @@ -2054,6 +2056,13 @@ export class GuildInvite<WithCounts extends boolean = boolean> extends BaseInvit
public delete(reason?: string): Promise<void>;
}

export type InviteFlagsString = keyof typeof InviteFlags;

export class InviteFlagsBitField extends BitField<InviteFlagsString> {
public static Flags: typeof InviteFlags;
public static resolve(bit?: BitFieldResolvable<InviteFlagsString, number>): number;
}

export class GroupDMInvite<WithCounts extends boolean = boolean> extends BaseInvite<WithCounts> {
public readonly type: InviteType.GroupDM;
public channel: PartialGroupDMChannel | null;
Expand Down