I’m currently trying to get the total amount of text channels and voice channels to display in my embed, when I try to filter them as I did in discord.js v12 it gives me an output of 0 but if I use no filter and do guild.channels.cache.size, it prints 4 which is the correct amount ( 2 text channels, 1 voice channel , 1 category channel).
If anyone can explain why it’s printing 0 and not the correct amount of text/voice channels that would be amazing, I’ve searched everywhere and can’t find a reason why it wouldn’t work.
JavaScript
x
35
35
1
const { SlashCommandBuilder } = require('@discordjs/builders');
2
const { MessageEmbed } = require('discord.js');
3
4
// EXPORT SERVERINFO COMMAND DATA TO NODE
5
module.exports = ({
6
data: new SlashCommandBuilder()
7
.setName('serverinfo')
8
.setDescription('Basic Server Info.'),
9
async execute(interaction) {
10
// REFERENCE THE GUILD
11
const guild = interaction.guild;
12
// CREATE TEST EMBED
13
const serverInfoEmbed = new MessageEmbed();
14
serverInfoEmbed.setColor('#36393F');
15
serverInfoEmbed.setAuthor('Fyce Bot - /serverinfo', interaction.user.avatarURL(), 'https://github.com/ttommie/fyce-bot/');
16
serverInfoEmbed.setTitle('Server Information');
17
serverInfoEmbed.setThumbnail(guild.iconURL());
18
serverInfoEmbed.addFields(
19
{ name: 'Name', value: `${guild.name}`, inline: true },
20
{ name: 'u200B', value: 'u200B', inline: true },
21
{ name: 'Owner', value: `<@${guild.ownerId}>`, inline: true },
22
{ name: 'Total Members', value: `${guild.memberCount}`, inline: true },
23
{ name: 'Users Count', value: `${guild.members.cache.filter(member => !member.user.bot).size}`, inline: true },
24
{ name: 'Bots Count', value: `${guild.members.cache.filter(member => member.user.bot).size}`, inline: true },
25
{ name: 'Text Channels', value: `${guild.channels.cache.filter(channels => channels.type === 'text').size}`, inline: true }, // PROBLEM HERE
26
{ name: 'Voice Channels', value: `${guild.channels.cache.filter(c => c.type === 'voice').size}`, inline: true }, // PROBLEM HERE
27
{ name: 'Roles Count', value: `${guild.roles.cache.size}`, inline: true },
28
);
29
serverInfoEmbed.setFooter(`${guild.name} - Date Created`);
30
serverInfoEmbed.setTimestamp(`${guild.createdAt.toUTCString().substr(0, 16)}`);
31
32
await interaction.reply({ embeds: [serverInfoEmbed] });
33
},
34
});
35
Advertisement
Answer
Discord.js v13 changed the possible values of Channel.type
.
Here is how you change it
JavaScript
1
12
12
1
//text channel filter
2
- guild.channels.cache.filter(c => c.type === 'text')
3
+ guild.channels.cache.filter(c => c.type === 'GUILD_TEXT')
4
5
//vc filter
6
- guild.channels.cache.filter(c => c.type === 'voice')
7
+ guild.channels.cache.filter(c => c.type === 'GUILD_VOICE')
8
9
//category filter
10
- guild.channels.cache.filter(c => c.type === 'category')
11
+ guild.channels.cache.filter(c => c.type === 'GUILD_CATEGORY')
12
Replace whatever is preceded with a -
with the text below which is preceded with a +