How to get the number of voice channels in a guild?

后端 未结 1 535
情歌与酒
情歌与酒 2021-01-29 07:27

I\'m creating a \"server info\" command for my Discord bot: how can I display the number of voice channels?

1条回答
  •  心在旅途
    2021-01-29 07:51

    • Retrieve a Collection of all the guild's channels with Guild.channels.
    • Use Collection.filter() to retrieve a new Collection containing only voice channels.
      • Compare GuildChannel.type with voice in the predicate function.
    • Read the size property of the new Collection.

    Consider this example:

    const voiceChannelCount = message.guild.channels.filter(c => c.type === 'voice').size;
    

    0 讨论(0)
提交回复
热议问题