D
D
DefaultCR2021-02-16 18:49:19
JavaScript
DefaultCR, 2021-02-16 18:49:19

How to count the time spent in a voice channel?

I have a code that reacts to voice entry and exit. At the entrance it is written "who and where joined", at the exit "who came from where". How can I change it so that it also counts the time spent in the voice channel?

global.bot.on('voiceStateUpdate', (oldState, newState) => {
            const date = new Date();
            const member = newState.member;
            const currenttime = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
            const oldchan = oldState.channel;
            const newchan = newState.channel;
            if (newchan != oldchan) {
                if (oldchan) {
                    if (newchan) {
                        console.log(`${currenttime} - ${member.nickname || member.user.username} сменил канал с ${oldchan.name} на ${newchan.name}`);
                    }
                    else {
                        console.log(`${currenttime} - ${member.nickname || member.user.username} ушёл ${oldchan.name}`);
                    }
                }
                else if (newchan) {
                    console.log(`${currenttime} - ${member.nickname || member.user.username} присоединился ${newchan.name}`);
                }
            }
        });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question