【问题标题】:Getting number of Category's in a guild discord.js V13在公会 discord.js V13 中获取类别的数量
【发布时间】:2021-10-05 08:52:18
【问题描述】:

对于我的机器人,我正在制作一个服务器信息命令,目前我似乎无法获得公会中类别的数量,因此当用户运行 !serverinfo 时,有一个嵌入并在 类别 将显示一个数字。目前显示的数字是 0。我该如何解决这个问题?

代码

 const channels = message.guild.channels.cache;

  const embed = new MessageEmbed()
  .setAuthor(message.guild.name, message.guild.iconURL({dynamic: true}))
  .setThumbnail(message.guild.iconURL({dynaic: true}))
  .addField(`Owner`, `${owner.user.tag}`,true)
  .addField(`Categorys`, `${channels.filter(channel => channel.type === "category").size}`,true)

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    你应该得到类别的数量

    message.guild.channels.cache.filter(ch => ch.type === 'GUILD_CATEGORY').size
    

    【讨论】:

      【解决方案2】:

      您可以通过获取所有频道(将它们全部缓存)然后过滤类别来获取它。

      message.guild.channels.fetch().then(channels => {
        console.log(channels.filter(c => c.type === "GUILD_CATEGORY").size)
      })
      

      相关文档: GuildChannelManager.fetch() Channel.type

      【讨论】:

        猜你喜欢
        • 2021-11-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-02
        • 1970-01-01
        • 2022-01-13
        • 2021-11-04
        • 2021-11-09
        • 2022-01-25
        相关资源
        最近更新 更多