How can I consistently get the parent channel of a public thread?
DJS says thread.parent can be null. Reading issues and PRs (#8453, #8466), it seems like this occurs when a thread is created without a starting message in a channel. But it still belongs to a parent channel. So how can I get this parent channel?
23 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.if channel uncached
Hmmm I see, how would I fetch it? Since
parentId
is also nullableno
fetchParent
in sightI guess I could fetchStarterMessage and then fetch that channel ID
might be because partial, apparently could be in dm channels?
You can def not have threads in DMs lol
Maybe group DMs?
Nah checked that too
that's nice, misleading because .partial isn't overridden lol
I guess I can use that
starterMessageId === parentChannelId
and just fetch the parent that way
Actually no, because people can delete the starter message
So that doesn't work in some cases eitherdapi docs also says nullable, not why tho
Weird, good to know it's not a DJS bug at least
But I still need to figure out how to consistently fetch it lol
wait, no it's not a thread channel structure it shows for, it's for all Channel structures in dapi docs
and it would be null if channel has no category
Doesn't mention it being null here: https://discord.com/developers/docs/topics/threads#threads
TBH I don't know my way around DAPI docs
So thread inherits that from Channel?
yes
so ig might be a small mistake with typings 🤷♂️
I'll open an issue and see what the response is, thank you for your help
aha
https://github.com/discordjs/discord.js/pull/8467
I could've sworn I saw something like this before but couldn't find it when I looked around
This makes it seem intentional..
GitHub
ThreadChannel#fetchStartermessage throws sync error if parent is n...
Which package is this bug report for? discord.js Issue description Create thread (not on a message) Weep because you catch the promise rejection, but it still errors out discord.js/src/structures/T...
So it seems like this.parent is null if you create a thread that is not on a message... which is very weird because it still belongs to a channel
Wonder if that's the API doing that
Wait... I get it.
There are public threads and private threads
Private threads are basically like group DMs and don't belong to a channel
Duh
I was looking for
PublicThreadChannel
I'm still not sure exactly how I would get the parent from a PublicThreadChannel
, so I'll leave the thread open because that would be good to know. But I'm not blocked by this anymore as what I really wanted was to know a GuildMember's permission in this thread, which now works with member.PermissionsIn(thread)
Update: I now need to get the parentId
of a PublicThreadChannel
. It cannot be null
. Any ideas?
bump<:issue_open:852714230280486942> #8471 in discordjs/discord.js by MarcusOtter opened <t:1660188726:R>
parentId
should never be null on PublicThreadChannel