`parentId` should never be null on `PublicThreadChannel`
See original GitHub issueWhich 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:
- Created a year ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Again, all threads behave exactly the same in regards to
parentId
andparent
. It doesn’t have to do with the type of thread, its where its received fromSweepers 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 ifparentId
can ever be missing.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)