简体   繁体   English

如何查看语音频道中有多少成员?

[英]How to check how many member are in a voice channel?

Is there a way to check how many members are in a voice channel or if it's empty in discord.js (V. 13.8.1)?有没有办法检查语音频道中有多少成员,或者在 discord.js (V. 13.8.1) 中是否为空?

I have already tried this我已经试过了

async function usercount(voiceState){
    let users = await(voiceState.channel.fetch.memberCount);
    console.log(users)
}

VoiceChannel#members is a collection of the members in a voice-based channel. VoiceChannel#members是基于语音的频道中成员的集合。 Collection's have a size property, so something like this should work:集合有一个size属性,所以这样的东西应该可以工作:

function usercount(voiceState) {
  let { members } = voiceState.channel;

  console.log(members);

  return members.size;
}

Can use the VoiceChannel.members.size to get how many members are in the channel.可以使用VoiceChannel.members.size来获取频道中有多少成员。

Here's an example:这是一个例子:

const GuildMember = new Discord.GuildMember(); // This shall be the command author.

if (GuildMember.voice.channel) 
{      
    console.log(GuildMember.voice.channel.members.size);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM