#Channel.id, .type etc returning undefined.

5 messages · Page 1 of 1 (latest)

sterile loom
#

I'm trying to loop through all text channels in a guild however am running into some issues.

        guild.channels.fetch().then(() => {
            console.log('All channels have been cached for the guild');

            let channels = guild.channels.cache;

            for(const channel of channels) {
                console.log(channel.type)
                if(channel.type === 'GUILD_TEXT') {
                    console.log(channel.id)
                }
            }
        });```
Whenever I run this,  ``console.log(channel.type)`` ALWAYS logs ``undefined`` in console. This is also the same for any property of channel such as ``channel.id``, ``channel.createdAt`` etc. If I print ``channel`` just by it self though it prints the channel object as seen below:

https://pastebin.com/raw/dGBYDRVg
flint turret
#

• 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.

sterile loom
#

no errors either, just it logs undefined

flint hatch
#

all channels are cached with the GUILDS intent so fetching is unnecessary

#

id is returning undefined because that log is showing no id