Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

guild.channels.filter is not a function discord.js

I was trying to make a user presence but I am getting an error:

guild.channels.filter is not a function

My code:

const Discord = require('discord.js');
const guild = client.guilds.cache.get('847071265100791849');

const categoryChannels = guild.channels.filter(
  (channel) => channel.type === '886241068855734273'
);

categoryChannels.forEach((channel) => {
  const statuss = channel.children.size - 2;
  client.user.setPresence({
    status: 'online',
    activities: [{ name: `${statuss} Open Tickets ✉️`, type: 'WATCHING' }],
  });
});

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

guild.channels returns a GuildChannelManager so it doesn’t have a filter method. You can fetch all channels that returns a collection, and then you can use filter on that:

const guild = client.guilds.cache.get('847071265100791849');
const channels = await guild.channels.fetch();
const categoryChannel = channels.filter(
  channel => channel.type === '886241068855734273'
);

That channel.type won’t work though as that snowflake is not one of the ChannelTypes. You’ll either need to use a valid ChannelType or use channel.id.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading