I want to get a channel with only an ID given. So the way the docs describe is like this: client.channels.cache.get('channel id'), and that's also how I am doing it.
But by printing out the cache I see that the cache Map is empty (length = 0).
The thing is, placing the console.log(client.channels.cache) in my client "ready" event listener, it gets printed out.
I read that this error could appear if the client is not logged in properly, but this can not be the case since I call the function with a command and the console log in the "ready" event listener is called instantly after the program is started and works better.
So there must be something else I am missing.
If you know the channel ID, you could simply fetch the channel by this ID. If it's cached, it returns the cached channel:
const channel = await client.channels.fetch(CHANNEL_ID)
console.log(channel)
fetch() returns a Promise, so you'll need to use await in an async function, or then methods.