Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message.inGuild() can be false for messages in closed threads fetched with allowUnknownGuild #10155

Open
Jochem-W opened this issue Feb 27, 2024 · 3 comments

Comments

@Jochem-W
Copy link

Which package is this bug report for?

discord.js

Issue description

When fetching a closed thread with allowUnknownGuild set to true, messages fetched in that channel will have no guild, no guildId, and Message.inGuild() will return false, even if the channel itself has a guild. This seems to happen for all closed threads. Setting allowUnknownGuild to false or omitting it entirely prevents the issue from happening.

Steps to reproduce:

  1. Create a thread in a server with your bot
  2. Close the thread
  3. Copy the thread ID into the code sample below

Expected behaviour:
The thread is in a guild, and thread.guild returns the guild, so, logically, each message should also have a guild.

Actual behaviour:
The messages don't have a guild, and isGuild returns false. The console.log is executed.

Code sample

import { Client, GatewayIntentBits } from "discord.js"

const token = "BOT_TOKEN"
const closedThreadId = "CHANNEL_ID"

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
})

client.addListener("ready", async () => {
  const thread = await client.channels.fetch(closedThreadId, {
    allowUnknownGuild: true,
  })

  if (!thread || !thread.isThread() || !thread.archived) {
    await client.destroy()
    throw new Error("Invalid channel")
  }

  const messages = await thread.messages.fetch()
  if (thread.guild && !messages.every((message) => message.inGuild())) {
    console.log(
      "Despite the channel having a guild, the messages aren't inGuild",
    )
  }

  await client.destroy()
})

await client.login(token)

Versions

  • discord.js 14.14.1
  • Node.js 21.6.1
  • Windows 11 22621.3155

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildMessages, MessageContent

I have tested this issue on a development release

efa3cac

@Jiralite
Copy link
Member

Jiralite commented Feb 27, 2024

Why are you reporting this as an issue? It's documented to return errors:

image

@Jochem-W
Copy link
Author

I didn't know it was such a problematic option even if the guild is already cached. I'm guessing no PRs will be accepted for it either then?

@Jiralite
Copy link
Member

It's especially problematic on uncached guilds, but we'll look into it for sure, just to be on the safe side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants