Cursed
Cursed

Reputation: 1003

Person time count in the channel

My code doesn't count the time a guy is on the voice channel.
This is for my discord server, running js and sqlite. All I tried is on that code

module.exports.run = async(bot, message, args) => {
  bot.on('voiceStateUpdate', (oldMember, newMember) => {
    let newUserChannel = newMember.voiceChannel;
    let oldUserChannel = oldMember.voiceChannel;

    if (oldUserChannel === undefined && newUserChannel !== undefined) {
      let totalSeconds = (newUserChannel.uptime / 1000);
      let days = Math.floor(totalSeconds / 86400);
      let hours = Math.floor(totalSeconds / 3600);
      totalSeconds %= 3600;
      let minutes = Math.floor(totalSeconds / 60);
      let seconds = totalSeconds % 60;
      let uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
      console.log(uptime);
      console.log("hi");
    } else if (newUserChannel === undefined) {
      console.log("bye");
    }
  });
}

I want it to count for each user on voice channel the time he is on it and send it to a db.

Upvotes: 0

Views: 2239

Answers (1)

cody.figler
cody.figler

Reputation: 23

Unfortunately, .uptime is not a property of .voiceChannel.

After looking through the docs for a while, I do not see a way to see how long they have been in a channel.

My solution for this would be to store the time that they join the channel, and then subtract that from the time they leave.

Hope I could help!

Source: Discord.JS Docs for #VoiceChannel

Upvotes: 1

Related Questions