diff --git a/index.d.ts b/index.d.ts index 6cd2a5d39..2d6b9c406 100644 --- a/index.d.ts +++ b/index.d.ts @@ -150,6 +150,7 @@ declare namespace Eris { // Invite type InviteTargetTypes = Constants["InviteTargetTypes"][keyof Constants["InviteTargetTypes"]]; + type InviteTypes = Constants["InviteTypes"][keyof Constants["InviteTypes"]]; // Message type ActionRowComponents = Button | SelectMenu; @@ -2353,8 +2354,12 @@ declare namespace Eris { getGuildWidget(guildID: string): Promise; getGuildWidgetImageURL(guildID: string, style?: GuildWidgetStyles): string; getGuildWidgetSettings(guildID: string): Promise; + /** @deprecated */ getInvite(inviteID: string, withCounts?: false, withExpiration?: boolean, guildScheduledEventID?: string): Promise>; + /** @deprecated */ getInvite(inviteID: string, withCounts: true, withExpiration?: boolean, guildScheduledEventID?: string): Promise>; + getInvite(inviteID: string, withCounts?: false, guildScheduledEventID?: string): Promise>; + getInvite(inviteID: string, withCounts: true, guildScheduledEventID?: string): Promise>; getJoinedPrivateArchivedThreads(channelID: string, options?: GetArchivedThreadsOptions): Promise>; getMessage(channelID: string, messageID: string): Promise; getMessageReaction(channelID: string, messageID: string, reaction: string, options?: GetMessageReactionOptions): Promise; @@ -3046,6 +3051,7 @@ declare namespace Eris { // @ts-ignore: Property is only not null when invite metadata is supplied createdAt: CT extends "withMetadata" ? number : null; expiresAt?: CT extends "withCount" ? number | null : null; + flags?: number; guild: CT extends "withMetadata" ? Guild // Invite with Metadata always has guild prop : CH extends Extract // Invite without Metadata @@ -3062,6 +3068,7 @@ declare namespace Eris { /** @deprecated */ stageInstance: CH extends StageChannel ? InviteStageInstance : null; temporary: CT extends "withMetadata" ? boolean : null; + type: InviteTypes; uses: CT extends "withMetadata" ? number : null; constructor(data: BaseData, client: Client); delete(reason?: string): Promise; diff --git a/lib/Client.js b/lib/Client.js index 97f9ea634..d8698938d 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -3019,14 +3019,18 @@ class Client extends EventEmitter { * Get info on an invite * @arg {String} inviteID The ID of the invite * @arg {Boolean} [withCounts] Whether to fetch additional invite info or not (approximate member counts, approximate presences, channel counts, etc.) - * @arg {Boolean} [withExpiration] Whether to fetch the expiration time or not + * @arg {Boolean} [withExpiration] [DEPRECATED] Whether to fetch the expiration time or not. This is deprecated because Discord will now always return the expiration date * @arg {String} [guildScheduledEventID] The guild scheduled event to include with the invite * @returns {Promise} */ - getInvite(inviteID, withCounts, withExpiration, guildScheduledEventID) { + getInvite(inviteID, withCounts, _withExpiration, guildScheduledEventID) { + if (typeof _withExpiration === "string") { + guildScheduledEventID = _withExpiration; + } else if (typeof _withExpiration === "boolean") { + emitDeprecation("GET_INVITE_WITH_EXPIRATION"); + } return this.requestHandler.request("GET", Endpoints.INVITE(inviteID), true, { with_counts: withCounts, - with_expiration: withExpiration, guild_scheduled_event_id: guildScheduledEventID, }).then((invite) => new Invite(invite, this)); } diff --git a/lib/Constants.d.ts b/lib/Constants.d.ts index 402157741..75dcf237e 100644 --- a/lib/Constants.d.ts +++ b/lib/Constants.d.ts @@ -235,6 +235,7 @@ export default interface Constants { "DEVELOPER_SUPPORT_SERVER", "DISCOVERABLE", "FEATURABLE", + "GUESTS_ENABLED", "INVITES_DISABLED", "INVITE_SPLASH", "MEMBER_VERIFICATION_GATE_ENABLED", @@ -357,10 +358,18 @@ export default interface Constants { APPLICATION_COMMAND_AUTOCOMPLETE: 4; MODAL_SUBMIT: 5; }; + InviteFlags: { + IS_GUEST_INVITE: 1; + }; InviteTargetTypes: { STREAM: 1; EMBEDDED_APPLICATION: 2; }; + InviteTypes: { + GUILD: 0; + GROUP_DM: 1; + FRIEND: 2; + }; Locales: { BULGARIAN: "bg"; CZECH: "cs"; diff --git a/lib/Constants.js b/lib/Constants.js index c0de89331..fa55bb860 100644 --- a/lib/Constants.js +++ b/lib/Constants.js @@ -275,6 +275,7 @@ module.exports.GuildFeatures = [ "DEVELOPER_SUPPORT_SERVER", "DISCOVERABLE", "FEATURABLE", + "GUESTS_ENABLED", "INVITE_SPLASH", "INVITES_DISABLED", "MEMBER_VERIFICATION_GATE_ENABLED", @@ -436,11 +437,21 @@ module.exports.InteractionTypes = { MODAL_SUBMIT: 5, }; +module.exports.InviteFlags = { + IS_GUEST_INVITE: 1 << 0, +}; + module.exports.InviteTargetTypes = { STREAM: 1, EMBEDDED_APPLICATION: 2, }; +module.exports.InviteTypes = { + GUILD: 0, + GROUP_DM: 1, + FRIEND: 2, +}; + module.exports.Locales = { BULGARIAN: "bg", CZECH: "cs", diff --git a/lib/structures/Invite.js b/lib/structures/Invite.js index d9b82763f..92da320b7 100644 --- a/lib/structures/Invite.js +++ b/lib/structures/Invite.js @@ -14,6 +14,7 @@ const Member = require("./Member"); * @prop {String} code The invite code * @prop {Number?} createdAt Timestamp of invite creation * @prop {Number?} expiresAt Timestamp of invite expiration + * @prop {Number?} flags The invite flags. For now, if there are any invite flags, they will only be `1` (meaning this invite is a guest invite for a voice channel) * @prop {(Guild | Object)?} guild Info on the invite guild. If the guild is not cached, this will be an object with an `id` key. No other property is guaranteed. * @prop {User?} inviter The invite creator * @prop {Number?} maxAge How long the invite lasts in seconds @@ -25,6 +26,7 @@ const Member = require("./Member"); * @prop {Number?} targetType The type of the target application * @prop {User?} targetUser The user whose stream is displayed for the invite (voice channel only) * @prop {Boolean?} temporary Whether the invite grants temporary membership or not + * @prop {Number} type The type of invite. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/invite#invite-object-invite-types) for valid types * @prop {Number?} uses The number of invite uses */ class Invite extends Base { @@ -71,6 +73,12 @@ class Invite extends Base { } else { this.stageInstance = null; } + if (data.flags !== undefined) { + this.flags = data.flags; + } + if (data.type !== undefined) { + this.type = data.type; + } this.targetApplicationID = data.target_application !== undefined ? data.target_application.id : null; this.targetType = data.target_type !== undefined ? data.target_type : null; this.targetUser = data.target_user !== undefined ? this._client.users.update(data.target_user, this._client) : null; @@ -102,6 +110,7 @@ class Invite extends Base { "channel", "code", "createdAt", + "flags", "guild", "maxAge", "maxUses", diff --git a/lib/structures/Member.js b/lib/structures/Member.js index 9f87aaac7..a0957545b 100644 --- a/lib/structures/Member.js +++ b/lib/structures/Member.js @@ -34,7 +34,7 @@ const VoiceState = require("./VoiceState"); * @prop {String?} globalName The user's display name, if it is set. For bots, this is the application name * @prop {Guild} guild The guild the member is in * @prop {String} id The ID of the member - * @prop {Number?} joinedAt Timestamp of when the member joined the guild + * @prop {Number?} joinedAt Timestamp of when the member joined the guild (Note: Member objects retrieved from `Client#voiceStateUpdate` events will have `joinedAt` set as `null` if the member was invited as a guest) * @prop {String} mention A string that mentions the member * @prop {String?} nick The server nickname of the member * @prop {Boolean?} pending Whether the member has passed the guild's Membership Screening requirements diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 66e682511..c90f9538c 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -4,6 +4,7 @@ const warningMessages = { DEFAULT_PERMISSION: "Passing a defaultPermission for application commands is deprecated. Use defaultMemberPermissions instead.", DELETE_MESSAGE_DAYS: "Passing the deleteMessageDays parameter to banGuildMember is deprecated. Use an options object with deleteMessageSeconds instead.", DM_REACTION_REMOVE: "Passing a userID when using removeMessageReaction() in a DMChannel is deprecated. This behavior is no longer supported by Discord.", + GET_INVITE_WITH_EXPIRATION: "Passing withExpiration to getInvite() is deprecated. This is because Discord now always sends an expiration date when fetching an invite.", GET_REACTION_BEFORE: "Passing the before parameter to getMessageReaction() is deprecated. Discord no longer supports this parameter.", MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead.", MESSAGE_REFERENCE: "Passing the content.messageReferenceID option to createMessage() is deprecated. Use the content.messageReference option instead.",