Skip to content

Commit bb67f3c

Browse files
Jiralitethehairy
andauthored
feat: Guest invites (#11055)
* feat: guest invites * types: add types * docs: add `InviteFlags` * docs: grammar Co-authored-by: Sören Stabenow <[email protected]> --------- Co-authored-by: Sören Stabenow <[email protected]>
1 parent 90813b3 commit bb67f3c

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

packages/discord.js/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ exports.Constants = require('./util/Constants.js');
2929
exports.Events = require('./util/Events.js').Events;
3030
exports.GuildMemberFlagsBitField = require('./util/GuildMemberFlagsBitField.js').GuildMemberFlagsBitField;
3131
exports.IntentsBitField = require('./util/IntentsBitField.js').IntentsBitField;
32+
exports.InviteFlagsBitField = require('./util/InviteFlagsBitField.js').InviteFlagsBitField;
3233
exports.LimitedCollection = require('./util/LimitedCollection.js').LimitedCollection;
3334
exports.MessageFlagsBitField = require('./util/MessageFlagsBitField.js').MessageFlagsBitField;
3435
exports.Options = require('./util/Options.js').Options;

packages/discord.js/src/structures/GuildInvite.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { Routes, PermissionFlagsBits, InviteType } = require('discord-api-types/v10');
44
const { DiscordjsError, ErrorCodes } = require('../errors/index.js');
5+
const { InviteFlagsBitField } = require('../util/InviteFlagsBitField.js');
56
const { BaseInvite } = require('./BaseInvite.js');
67
const { GuildScheduledEvent } = require('./GuildScheduledEvent.js');
78
const { IntegrationApplication } = require('./IntegrationApplication.js');
@@ -48,6 +49,17 @@ class GuildInvite extends BaseInvite {
4849
_patch(data) {
4950
super._patch(data);
5051

52+
if ('flags' in data) {
53+
/**
54+
* The flags of this invite.
55+
*
56+
* @type {Readonly<InviteFlagsBitField>}
57+
*/
58+
this.flags = new InviteFlagsBitField(data.flags).freeze();
59+
} else {
60+
this.flags ??= new InviteFlagsBitField().freeze();
61+
}
62+
5163
if ('guild' in data) {
5264
/**
5365
* The guild the invite is for. May include welcome screen data.

packages/discord.js/src/util/APITypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@
514514
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/InteractionResponseType}
515515
*/
516516

517+
/**
518+
* @external InviteFlags
519+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/InviteFlags}
520+
*/
521+
517522
/**
518523
* @external InviteType
519524
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/InviteType}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-disable jsdoc/check-values */
2+
'use strict';
3+
4+
const { InviteFlags } = require('discord-api-types/v10');
5+
const { BitField } = require('./BitField.js');
6+
7+
/**
8+
* Data structure that makes it easy to interact with a {@link GuildInvite#flags} bit field.
9+
*
10+
* @extends {BitField}
11+
*/
12+
class InviteFlagsBitField extends BitField {
13+
/**
14+
* Numeric invite flags.
15+
*
16+
* @type {InviteFlags}
17+
* @memberof InviteFlagsBitField
18+
*/
19+
static Flags = InviteFlags;
20+
}
21+
22+
/**
23+
* @name InviteFlagsBitField
24+
* @kind constructor
25+
* @memberof InviteFlagsBitField
26+
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
27+
*/
28+
29+
exports.InviteFlagsBitField = InviteFlagsBitField;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ import {
159159
InteractionContextType,
160160
InteractionResponseType,
161161
InteractionType,
162+
InviteFlags,
162163
InviteTargetType,
163164
InviteType,
164165
Locale,
@@ -2039,6 +2040,7 @@ export class BaseInvite<WithCounts extends boolean = boolean> extends Base {
20392040

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

2059+
export type InviteFlagsString = keyof typeof InviteFlags;
2060+
2061+
export class InviteFlagsBitField extends BitField<InviteFlagsString> {
2062+
public static Flags: typeof InviteFlags;
2063+
public static resolve(bit?: BitFieldResolvable<InviteFlagsString, number>): number;
2064+
}
2065+
20572066
export class GroupDMInvite<WithCounts extends boolean = boolean> extends BaseInvite<WithCounts> {
20582067
public readonly type: InviteType.GroupDM;
20592068
public channel: PartialGroupDMChannel | null;

0 commit comments

Comments
 (0)