使用discord.js显示类别中有多少个频道 [英] Show how many channels are in a category with discord.js

查看:42
本文介绍了使用discord.js显示类别中有多少个频道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用discord.js显示类别中的频道数量?

Is there a way how I can show how many channels are in a category with discord.js?

推荐答案

实际上有一种相当简单的方法.您可以从公会获取所有频道,然后循环浏览它们.然后,选择所有属于 category 类型的频道,并获取其 children 属性的大小.

There is actually a reasonably easy way of doing this. You can fetch all the channels from a guild and then loop through them. You then pick out all the channels which are of type category and get the size of their children property.

下面是一些代码,可以帮助您朝正确的方向前进.

Below is some code which will help you go in the right direction.

client.on("message", async message =>
{
    // Do all your validation and whatnot here
    ....

    const guild = message.guild;

    const categoryChannels = guild.channels.filter(channel => channel.type === "category");

    categoryChannels.forEach(channel => {
        console.log(`Category ${channel.name} has ${channel.children.size} channels`);
    });
});

尝试一下,让我知道它的进展!

Give it a try and let me know how it goes!

这篇关于使用discord.js显示类别中有多少个频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆