question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`parentId` should never be null on `PublicThreadChannel`

See original GitHub issue

Which package is this bug report for?

discord.js

Issue description

How it should be A PublicThreadChannel (ThreadChannel.type: ChannelType.GuildPublicThread | ChannelType.GuildNewsThread) should never have parentId === null.

How it is in DJS PublicThreadChannel.parentId and PublicThreadChannel.parent can both be null.

The problem It is not possible (to my knowledge) to safely get the parent channel of a PublicThreadChannel. There is no fetchParent(). And we cannot use <client>.channels.fetch(<thread>.parentId) because parentId can be null. How are we supposed to get the parent channel of a public thread?

Possibly related https://github.com/discordjs/discord.js/pull/8466

Code sample

async function getParentChannelId(thread: PublicThreadChannel): Promise<string> {
	return thread.parentId; // Type 'null' is not assignable to type 'string'.
}

Package version

discord.js@14.1.1

Node.js version

v16.13.2

Operating system

Windows

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMessages

I have tested this issue on a development release

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ckohencommented, Aug 11, 2022

Again, all threads behave exactly the same in regards to parentId and parent. It doesn’t have to do with the type of thread, its where its received from

Sweepers don’t affect the types, but it can be part of a situation where parentId is null.

As for partials, discord sometimes doesn’t send full objects, to save network bandwidth for things that most people won’t need. In the past, the resolved data for a slash commadn channel option didn’t contain parent_id (raw form from discord, same field though), so that field became nullable. Now that is no longer the case, so its probably worth another look to see if parentId can ever be missing.

1reaction
ckohencommented, Aug 11, 2022

parent is the same no matter what type of thread it is. because private threads do also belong to channels.

parent is only nullable because of the cache access. If you have the Guilds intent and don’t do funky (unsupported) stuff with limiting channel cache, in all likelihood you will never have parent: null. This is a technicality and is not followed everywhere in the lib (notably, messages), but since threads were added after it was noticed that channel cache isn’t technically guaranteed, it was decided that the types should actually be accurate.

parentId is always present so you can fetch the parent with <client>.channels.fetch(<thread>.parentId)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parent ID is null when creating child object through related list
Parent ID is null when creating child object through related list ... If those fields are missing, then the relationship will not be...
Read more >
VoiceChannel | Eris 0.17.1 - Abal.moe
Whether the channel is an NSFW channel or not. type Boolean .parentID ... The RTC region ID of the channel (automatic when null...
Read more >
TextChannel | Oceanic
parentID. parentID: null | string. The ID of the parent of this channel, if applicable. ... This will throw an error if the...
Read more >
`parentId` should never be null on `PublicThreadChannel ...
discordjs/discord.js: `parentId` should never be null on `PublicThreadChannel` ... How it should be A PublicThreadChannel ( ThreadChannel.type: ChannelType.
Read more >
MarcusOtter (MarcusOtter) - PullAnswer
`parentId` should never be null on `PublicThreadChannel`. 0 Likes 7 Replies. MarcusOtter. 2022-08-13. Needle does not warn if it's missing create threads ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found