Home > OS >  How can I show every voice channel ID/name of a guild with DiscordJS?
How can I show every voice channel ID/name of a guild with DiscordJS?

Time:01-27

I'm trying to get and show all the voice channels name from guild.

That's my code, that not working

client.on('ready', () => {

    client.channels.fetch().then(channel =>
    {
        console.log(channel.name)
    });

}

I'd like to list all names of voice channels (not text).

CodePudding user response:

First you have to retrieve all channels using the channel cache of your client object. Then you filter by their type:

let voiceChannels = client.channels.cache.filter(m => m.type === 'voice');
voiceChannels.forEach(channel => console.log(channel.name));

CodePudding user response:

Filter the channels by type ChannelType.GuildVoice then map them to their name and id.

// import or require ChannelType from discord.js

const allChannels = await client.channels.fetch();

const voiceChannels = allChannels
   .filter(ch => ch.type === ChannelType.GuildVoice);

console.log(
   voiceChannels
      .map(ch => `${ch.id} | ${ch.name}`)
      .join('\n')
);
  • Related