How can I check if an ID is a category?

How can I check if an ID is a category?
17 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
Danial
Danial2y ago
A category of the guilds your bot is in or...?
Joãozinho
JoãozinhoOP2y ago
yes
Danial
Danial2y ago
<Client>.channels.cache.has("id") It'll return boolean
Joãozinho
JoãozinhoOP2y ago
then it pulls all channels I want to see if it is just category
Danial
Danial2y ago
That doesn't pull the channel, it just checks if a category with that id exists in the cache
Joãozinho
JoãozinhoOP2y ago
TypeError: Cannot read properties of undefined (reading 'cache')
Danial
Danial2y ago
Show your code
Joãozinho
JoãozinhoOP2y ago
I got it, it returned true, but it is not a category is channel text
Danial
Danial2y ago
Oh, I get what you mean now, you'd first get the channel from the cache and then compare its type with ChannelType.GuildCategory
Joãozinho
JoãozinhoOP2y ago
yes* How do I get the channel?
d.js docs
d.js docs2y ago
const channel = client.channels.cache.get("222086648706498562");
const channel = guild.channels.cache.find(channel => channel.name === "general");
const channel = client.channels.cache.get("222086648706498562");
const channel = guild.channels.cache.find(channel => channel.name === "general");
- Caches in discord.js are Collections which extend the native Map structure. - learn more
Danial
Danial2y ago
The first one
Joãozinho
JoãozinhoOP2y ago
yes and to check the type? is channel.type?
Danial
Danial2y ago
Yes
Joãozinho
JoãozinhoOP2y ago
returned 0 :_:
Danial
Danial2y ago
Yes, you'd compare that with ChannelType.GuildCategory
Want results from more Discord servers?
Add your server