diff --git a/src/structures/Invite.js b/src/structures/Invite.js index be21bc3ce098..c123e527a80e 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -2,6 +2,7 @@ const Base = require('./Base'); const IntegrationApplication = require('./IntegrationApplication'); +const InviteStageInstance = require('./InviteStageInstance'); const { Error } = require('../errors'); const { Endpoints } = require('../util/Constants'); const Permissions = require('../util/Permissions'); @@ -112,6 +113,15 @@ class Invite extends Base { this.createdTimestamp = 'created_at' in data ? new Date(data.created_at).getTime() : null; this._expiresTimestamp = 'expires_at' in data ? new Date(data.expires_at).getTime() : null; + + /** + * The stage instance data if there is a public {@link StageInstance} in the stage channel this invite is for + * @type {?InviteStageInstance} + */ + this.stageInstance = + 'stage_instance' in data + ? new InviteStageInstance(this.client, data.stage_instance, this.channel.id, this.guild.id) + : null; } /** diff --git a/src/structures/InviteStageInstance.js b/src/structures/InviteStageInstance.js new file mode 100644 index 000000000000..c5874495e69d --- /dev/null +++ b/src/structures/InviteStageInstance.js @@ -0,0 +1,80 @@ +'use strict'; + +const Base = require('./Base'); +const Collection = require('../util/Collection'); + +/** + * Represents the data about a public {@link StageInstance} in an {@link Invite}. + * @extends {Base} + */ +class InviteStageInstance extends Base { + constructor(client, data, channelID, guildID) { + super(client); + + /** + * The ID of the stage channel this invite is for + * @type {Snowflake} + */ + this.channelID = channelID; + + /** + * The guild ID of the stage channel + * @type {Snowflake} + */ + this.guildID = guildID; + + /** + * The members speaking in the stage channel + * @type {Collection} + */ + this.members = new Collection(); + + this._patch(data); + } + + _patch(data) { + /** + * The topic of the stage instance + * @type {string} + */ + this.topic = data.topic; + + /** + * The number of users in the stage channel + * @type {number} + */ + this.participantCount = data.participant_count; + + /** + * The number of users speaking in the stage channel + * @type {number} + */ + this.speakerCount = data.speaker_count; + + this.members.clear(); + for (const rawMember of data.members) { + const member = this.guild.members.add(rawMember); + this.members.set(member.id, member); + } + } + + /** + * The stage channel this invite is for + * @type {?StageChannel} + * @readonly + */ + get channel() { + return this.client.channels.resolve(this.channelID); + } + + /** + * The guild of the stage channel this invite is for + * @type {?Guild} + * @readonly + */ + get guild() { + return this.client.guilds.resolve(this.guildID); + } +} + +module.exports = InviteStageInstance; diff --git a/typings/index.d.ts b/typings/index.d.ts index 8c7a27b4a615..694d6f8f433b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1192,6 +1192,19 @@ declare module 'discord.js' { public toJSON(): unknown; public toString(): string; public static INVITES_PATTERN: RegExp; + public stageInstance: InviteStageInstance | null; + } + + export class InviteStageInstance extends Base { + constructor(client: Client, data: unknown, channelID: Snowflake, guildID: Snowflake); + public channelID: Snowflake; + public guildID: Snowflake; + public members: Collection; + public topic: string; + public participantCount: number; + public speakerCount: number; + public readonly channel: StageChannel | null; + public readonly guild: Guild | null; } export class Message extends Base {