diff --git a/packages/discord.js/src/structures/Invite.js b/packages/discord.js/src/structures/Invite.js index 821bd3c08..5252dd7cf 100644 --- a/packages/discord.js/src/structures/Invite.js +++ b/packages/discord.js/src/structures/Invite.js @@ -151,12 +151,24 @@ class Invite extends Base { this.targetType ??= null; } + if ('channel_id' in data) { + /** + * The id of the channel this invite is for + * @type {?Snowflake} + */ + this.channelId = data.channel_id; + } + if ('channel' in data) { /** * The channel this invite is for * @type {?Channel} */ - this.channel = this.client.channels._add(data.channel, this.guild, { cache: false }); + this.channel = + this.client.channels._add(data.channel, this.guild, { cache: false }) ?? + this.client.channels.resolve(this.channelId); + + this.channelId ??= data.channel.id; } if ('created_at' in data) { @@ -285,6 +297,7 @@ class Invite extends Base { presenceCount: false, memberCount: false, uses: false, + channel: 'channelId', inviter: 'inviterId', guild: 'guildId', }); diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index d945efb83..5cea58bf4 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1381,7 +1381,8 @@ export class InteractionWebhook extends PartialWebhookMixin() { export class Invite extends Base { private constructor(client: Client, data: RawInviteData); - public channel: NonThreadGuildBasedChannel | PartialGroupDMChannel; + public channel: NonThreadGuildBasedChannel | PartialGroupDMChannel | null; + public channelId: Snowflake | null; public code: string; public get deletable(): boolean; public get createdAt(): Date | null;