mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: Guest invites (#11055)
* feat: guest invites * types: add types * docs: add `InviteFlags` * docs: grammar Co-authored-by: Sören Stabenow <71461991+thehairy@users.noreply.github.com> --------- Co-authored-by: Sören Stabenow <71461991+thehairy@users.noreply.github.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<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.
|
||||
|
||||
@@ -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}
|
||||
|
||||
29
packages/discord.js/src/util/InviteFlagsBitField.js
Normal file
29
packages/discord.js/src/util/InviteFlagsBitField.js
Normal file
@@ -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;
|
||||
9
packages/discord.js/typings/index.d.ts
vendored
9
packages/discord.js/typings/index.d.ts
vendored
@@ -159,6 +159,7 @@ import {
|
||||
InteractionContextType,
|
||||
InteractionResponseType,
|
||||
InteractionType,
|
||||
InviteFlags,
|
||||
InviteTargetType,
|
||||
InviteType,
|
||||
Locale,
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user