Skip to content

Invite channel's guild may be incorrectly typed #10894

Open
@Jiralite

Description

@Jiralite

Which package is this bug report for?

discord.js

Issue description

When fetching an invite from a guild the client is not in, the guild of an invite is an InviteGuild, and the channel is handled as such:

if ('channel' in data) {
/**
* The channel this invite is for
* @type {?BaseChannel}
*/
this.channel =
this.client.channels._add(data.channel, this.guild, { cache: false }) ??
this.client.channels.resolve(this.channelId);
this.channelId ??= data.channel.id;
}

With that understood, imagine an invite was created in a text channel that the client was not in. Fetching this invite would yield the guild to be an InviteGuild and the channel being a TextChannel. A text channel's guild is typed as Guild, but this is incorrect—this.guild is an InviteGuild. The type is wrong.

Might be easier to tackle after #10888.

Code sample

import {
  Client,
  GatewayIntentBits,
  Events,
  TextChannel,
  Guild,
  InviteGuild,
} from "discord.js";

const client = new Client({ intents: GatewayIntentBits.Guilds });

client.on(Events.ClientReady, async () => {
  const invite = await client.fetchInvite("https://discord.gg/djs");

  console.log((invite.channel as TextChannel).guild instanceof Guild); // false.
  console.log((invite.channel as TextChannel).guild instanceof InviteGuild); // true.
});

void client.login();

Versions

  • discord.js f6da949
  • Node.js 22.13.1

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds

I have tested this issue on a development release

f6da949

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions