How to get all channels in a guild?

it looks like there is no way to get all channels in a guild, some posts were referring to .cache but thats not a real solution, how can i do it?
44 Replies
d.js toolkit
d.js toolkit•7mo 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!
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
ye but then not all of the channels show up, only channels where messages were sent
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
really? oh
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
so... i tried it and not all channels show up, most likely because they arent yet cached?
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
gimme a sec ill try again
console.log(client.guilds.cache.get(message.guild).channels);
^

TypeError: Cannot read properties of undefined (reading 'channels')
at Client.<anonymous> (/home/j44/Downloads/themer/tut/src/index.js:31:63)
at Client.emit (node:events:514:28)
at MessageCreateAction.handle (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/actions/MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE] (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/home/j44/Downloads/themer/tut/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/j44/Downloads/themer/tut/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/home/j44/Downloads/themer/tut/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.onMessage (/home/j44/Downloads/themer/tut/node_modules/@discordjs/ws/dist/index.js:988:14)

Node.js v20.9.0
console.log(client.guilds.cache.get(message.guild).channels);
^

TypeError: Cannot read properties of undefined (reading 'channels')
at Client.<anonymous> (/home/j44/Downloads/themer/tut/src/index.js:31:63)
at Client.emit (node:events:514:28)
at MessageCreateAction.handle (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/actions/MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE] (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
at WebSocketManager.emit (/home/j44/Downloads/themer/tut/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> (/home/j44/Downloads/themer/tut/node_modules/@discordjs/ws/dist/index.js:1173:51)
at WebSocketShard.emit (/home/j44/Downloads/themer/tut/node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.onMessage (/home/j44/Downloads/themer/tut/node_modules/@discordjs/ws/dist/index.js:988:14)

Node.js v20.9.0
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
oh okay looks like it gives me only some general information about the dc server
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs•7mo ago
property Guild#channels A manager of the channels belonging to this guild
Jannik44
Jannik44•7mo ago
No description
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Danial
Danial•7mo ago
That would be the manager, message.guild.channels.cache would show more information
Jannik44
Jannik44•7mo ago
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
wich one do you mean?
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
ah yes, message.guild.channels.cache shows a big amount of information, it sent also every thread so not the channels 😦
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
Jannik44
Jannik44•7mo ago
edit: both, i have both, threads and channels
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
duck
duck•7mo ago
is it that you're looking for a collection of guild channels excluding threads?
Jannik44
Jannik44•7mo ago
yes threads arent even channels are they?
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
duck
duck•7mo ago
and because they are, you'd want to filter the channel cache with <Guild>.channels.cache.filter() you're free to specifically check <Channel>.isThread() or check for specific types by checking <Channel>.type in case you weren't aware, categories are also channels, so if you were specifically just looking for text/voice channels, you'll want to filter those out as well
Jannik44
Jannik44•7mo ago
so isThread() gives me only threads right?
duck
duck•7mo ago
yes, so presumably you'd want to check that its not a thread
Jannik44
Jannik44•7mo ago
ye smth like isTextchannel()?
duck
duck•7mo ago
are you only looking for text channels?
Jannik44
Jannik44•7mo ago
text and voice channels im trying to modify their names
duck
duck•7mo ago
well you're likely also going to run into issues bulk editing channels what exactly is all this for?
Jannik44
Jannik44•7mo ago
oh no... im working on a bot that can apply themes and stuff for example adding an icon in front of every channel name
Danial
Danial•7mo ago
Yeah, that can get you rate limited real quickly Channel renaming rate limit is very high
Jannik44
Jannik44•7mo ago
how high exactly? have no problem with putting a few seconds/minutes between each edit
Danial
Danial•7mo ago
Twice every 10 minutes
Jannik44
Jannik44•7mo ago
thats acceptable so any idea how i can get text and voice channels?
Danial
Danial•7mo ago
You can filter using channel.type and ChannelType enum
Mac
Mac•7mo ago
yeah but isn't that per channel
duck
duck•7mo ago
even putting that aside, attempting to edit every channel in a guild has the potential to hit the global rate limit
Mac
Mac•7mo ago
what's the global rate limit?
Unknown User
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View