i’m trying to get all channels and delete these channels of category in discord v14, but throw me an error:
client.channels.cache.get(…).children.forEach is not a function
JavaScript
x
7
1
client.channels.cache.get("1234567890123456")
2
.children.forEach(channel => {
3
channel.delete();
4
})
5
6
// client.channels.cache.get("1234567890123456") Works but didn't give me the channels.
7
Advertisement
Answer
CategoryChannel.children
is type CategoryChannelChildManager
, which doesn’t have a forEach
method, so you can’t call forEach
on it. CategoryChannelChildManager.cache
is type Collection<Snowflake, GuildChannel>
, which does has a forEach
method, so you can call forEach
on it.
JavaScript
1
5
1
client.channels.cache.get("1234567890123456")
2
.children.cache.forEach([channelId, channel]=> {
3
channel.delete();
4
})
5