L
L
levarar2021-03-24 14:45:19
Node.js
levarar, 2021-03-24 14:45:19

Get the number of members in a voice channel (discord.js12)?

How can I find out the number of users in a voice channel? I have a system that counts the time of users in the voice channel, I want it to work, if there are more than two people in the voice channel, please tell me.
The code:

exports.execute = async (oldState, newState) => {
    if ((oldState.member && oldState.member.user.bot) || (newState.member && newState.member.user.bot)) {
        return;
    }

    if (!oldState.channelID && newState.channelID) {
        Activites.set(oldState.id, Date.now());
    }

    let data;

    if (!Activites.has(oldState.id)) {
        data = Date.now();
        Activites.set(oldState.id, data);
    }
    else {
        data = Activites.get(oldState.id);
    }

    let duration = Date.now() - data;

    if (oldState.channelID && !newState.channelID) {
        Activites.delete(oldState.id);
        vt.add(`stats.${oldState.guild.id}.${oldState.id}.channels.${oldState.channelID}`, duration);
        vt.set(`stats.${oldState.guild.id}.${oldState.id}.activity`, Date.now());
    }
    else if (oldState.channelID && newState.channelID) {
        Activites.set(oldState.id, Date.now());
        vt.add(`stats.${oldState.guild.id}.${oldState.id}.channels.${oldState.channelID}`, duration);
        vt.set(`stats.${oldState.guild.id}.${oldState.id}.activity`, Date.now());
    }
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-03-24
@levarar

newMember.channel.members.size

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question