How to properly check if the channel fetch is one where threads can be created?

Hi, I have the following code :
const supportChannelID = "an-id";
const channel = await guild.channels.fetch(supportChannelID);
const supportChannelID = "an-id";
const channel = await guild.channels.fetch(supportChannelID);
I would like to know the proper way to check that the channel supports thread creation in order to later write:
channel.threads.create({ ... })
channel.threads.create({ ... })
Because currently, using Typescript, with the code above it says that the property "threads" doesn't exist in StageChannel...
3 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
duck
duck12mo ago
putting aside the fact that non-thread guild channels are cached if you have the Guilds intent and therefore don't need to be fetched since you're getting a channel by hardcoded id, you realistically should know what type of channel it is and therefore you could cast/assert its type alternatively you could just check channel.type (by comparing with the appropriate member of the ChannelType enum) if you were looking for a more general solution, there isn't a specific typeguard for being able to create threads, so you'd need to utilize multiple typeguards to ensure that it's either textbased or thread only and that it's not a thread or voice channel alternatively you can just utilize the in operator
Apokalypt
ApokalyptOP12mo ago
Oh thank you, until now I was using the "in" keyword but I think I will switch to the check with the type property WumpsHeartyLove Just to explain why I don't force the type even if I know it, it's juste because I don't trust data. I always perform controls to be sure that if the source of the data change later (user input) I don't have to make many changes since all controls are already there
Want results from more Discord servers?
Add your server