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

parentId should never be null on PublicThreadChannel #8471

Open
MarcusOtter opened this issue Aug 11, 2022 · 7 comments
Open

parentId should never be null on PublicThreadChannel #8471

MarcusOtter opened this issue Aug 11, 2022 · 7 comments

Comments

@MarcusOtter
Copy link
Contributor

MarcusOtter commented Aug 11, 2022

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
#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

@ckohen
Copy link
Member

ckohen commented 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)

@MarcusOtter
Copy link
Contributor Author

MarcusOtter commented Aug 11, 2022

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

That's my misconception, but that makes this even weirder, because ThreadChannel.partial is exposed. I thought this was because private threads are a sort of DM channel. You can definitely not make threads in DMs, so I guess this is a type bug.

parentId is always present so you can fetch the parent with .channels.fetch(.parentId)

If that was the case, that would be great.

image

@ckohen
Copy link
Member

ckohen commented Aug 11, 2022

ah.....right, the minor detail of interactions.

So, to get the parent, try <thread>.parent first. If that doesn't exist it's most likely because parentId is missing, so .fetch() the thread and check if parentId exists. If it does, fetch with it as mentioned before, if not, throw an error cause you can't do anything else

@MarcusOtter
Copy link
Contributor Author

I don't know much about partials so I have no comments there. But I'm sorry, I don't really understand why parentId would ever be null on a public thread. Surely that's a DJS issue?

@MarcusOtter MarcusOtter changed the title parent should never be null on PublicThreadChannel parentId should never be null on PublicThreadChannel Aug 11, 2022
@MarcusOtter
Copy link
Contributor Author

Also, re:

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.

I have sweepers setup for threads, don't know if that would affect this. Probably?

@ckohen
Copy link
Member

ckohen commented 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.

@MarcusOtter
Copy link
Contributor Author

Perhaps add typings label and remove need repro?

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

4 participants