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 toolkit11mo 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
Danial11mo ago
A category of the guilds your bot is in or...?
Joãozinho
Joãozinho11mo ago
yes
Danial
Danial11mo ago
<Client>.channels.cache.has("id") It'll return boolean
Joãozinho
Joãozinho11mo ago
then it pulls all channels I want to see if it is just category
Danial
Danial11mo ago
That doesn't pull the channel, it just checks if a category with that id exists in the cache
Joãozinho
Joãozinho11mo ago
TypeError: Cannot read properties of undefined (reading 'cache')
Danial
Danial11mo ago
Show your code
Joãozinho
Joãozinho11mo ago
I got it, it returned true, but it is not a category is channel text
Danial
Danial11mo 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ãozinho11mo ago
yes* How do I get the channel?
d.js docs
d.js docs11mo 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
Danial11mo ago
The first one
Joãozinho
Joãozinho11mo ago
yes and to check the type? is channel.type?
Danial
Danial11mo ago
Yes
Joãozinho
Joãozinho11mo ago
returned 0 :_:
Danial
Danial11mo ago
Yes, you'd compare that with ChannelType.GuildCategory