Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord js v13 channel filter not working

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.

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');

// EXPORT SERVERINFO COMMAND DATA TO NODE
module.exports = ({
    data: new SlashCommandBuilder()
        .setName('serverinfo')
        .setDescription('Basic Server Info.'),
    async execute(interaction) {
        // REFERENCE THE GUILD
        const guild = interaction.guild;
        // CREATE TEST EMBED
        const serverInfoEmbed = new MessageEmbed();
        serverInfoEmbed.setColor('#36393F');
        serverInfoEmbed.setAuthor('Fyce Bot - /serverinfo', interaction.user.avatarURL(), 'https://github.com/ttommie/fyce-bot/');
        serverInfoEmbed.setTitle('Server Information');
        serverInfoEmbed.setThumbnail(guild.iconURL());
        serverInfoEmbed.addFields(
            { name: 'Name', value: `${guild.name}`, inline: true },
            { name: '\u200B', value: '\u200B', inline: true },
            { name: 'Owner', value: `<@${guild.ownerId}>`, inline: true },
            { name: 'Total Members', value: `${guild.memberCount}`, inline: true },
            { name: 'Users Count', value: `${guild.members.cache.filter(member => !member.user.bot).size}`, inline: true },
            { name: 'Bots Count', value: `${guild.members.cache.filter(member => member.user.bot).size}`, inline: true },
            { name: 'Text Channels', value: `${guild.channels.cache.filter(channels => channels.type === 'text').size}`, inline: true }, // PROBLEM HERE 
            { name: 'Voice Channels', value: `${guild.channels.cache.filter(c => c.type === 'voice').size}`, inline: true }, // PROBLEM HERE 
            { name: 'Roles Count', value: `${guild.roles.cache.size}`, inline: true },
        );
        serverInfoEmbed.setFooter(`${guild.name} - Date Created`);
        serverInfoEmbed.setTimestamp(`${guild.createdAt.toUTCString().substr(0, 16)}`);

        await interaction.reply({ embeds: [serverInfoEmbed] });
    },
});
like image 735
Tommie Avatar asked Nov 25 '25 07:11

Tommie


1 Answers

Discord.js v13 changed the possible values of Channel.type.

Here is how you change it

//text channel filter
- guild.channels.cache.filter(c => c.type === 'text')
+ guild.channels.cache.filter(c => c.type === 'GUILD_TEXT')

//vc filter
- guild.channels.cache.filter(c => c.type === 'voice')
+ guild.channels.cache.filter(c => c.type === 'GUILD_VOICE')

//category filter
- guild.channels.cache.filter(c => c.type === 'category')
+ guild.channels.cache.filter(c => c.type === 'GUILD_CATEGORY')

Replace whatever is preceded with a - with the text below which is preceded with a +

like image 184
MrMythical Avatar answered Nov 26 '25 23:11

MrMythical



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!