How i get the Threads property of the channel where slash commands were fired

Someone can help me? I need a TextChannel to create a private thread, i'm trying to use the channel that interaction returns, but it returns a TextBasedChannel, where i can't to get the .Threads property. What i need to use, to get the Textchannel where the interaction were fired
No description
22 Replies
d.js toolkit
d.js toolkit8mo 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! - Marked as resolved by OP
TÆMBØ
TÆMBØ8mo ago
You'd want to use a combination of - interaction.inCachedGuild() - !interaction.channel.isThread() - !interaction.channel.isVoiceBased() To ensure the channel is from a cached guild, isn't voice-based, and isn't a thread itself, which should then mean it's a NewsChannel or TextChannel with threads
orion
orionOP8mo ago
It still a TextBasedChannel
No description
orion
orionOP8mo ago
@TAEMBO.md
TÆMBØ
TÆMBØ8mo ago
Because you missed the first typeguard I mentioned, and you also need to ensure it's not null
orion
orionOP8mo ago
oh, my bad but i can't get the interaction.inCachedGuild(), my interaction is a ChatInputCommandInteraction
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs8mo ago
:method: ChatInputCommandInteraction#inCachedGuild @14.15.3 Indicates whether or not this interaction is both cached and received from a guild.
orion
orionOP8mo ago
No description
orion
orionOP8mo ago
i don't know if i doing right
TÆMBØ
TÆMBØ8mo ago
I don't see where you're calling the inCachedGuild() method there
orion
orionOP8mo ago
my bad again, i'm was writing wrong, lol 🤦‍♂️
orion
orionOP8mo ago
but the channel still a TextBasedChannel
No description
TÆMBØ
TÆMBØ8mo ago
You're negating your inCachedGuild() call there with your ! before it, remove that
orion
orionOP8mo ago
Same
No description
orion
orionOP8mo ago
Its weird, because it still a null
TÆMBØ
TÆMBØ8mo ago
I would try restarting your TS server (or simply reopening your IDE), as I'm not able to reproduce this on my end Well, hold on, what is channel there in your log You're narrowing the types on interaction.channel, but not on that channel variable you have
orion
orionOP8mo ago
🤦‍♂️
orion
orionOP8mo ago
I get a GuildTextBasedChannel now
No description
TÆMBØ
TÆMBØ8mo ago
Remove the optional chaining operators ? before isThread() and isVoiceBased(), as you've already determined earlier that channel isn't null
TÆMBØ
TÆMBØ8mo ago
No description
orion
orionOP8mo ago
that's worked really thanks for the help and my bad for this mistakes, lol ❤️

Did you find this page helpful?