Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

659
Views
How can I make my bot counting how many time a user has a role?

I want to make a bot with discord.js v12 to count how many time a user has a role and then send it in a channel with a webhook. My problem is how to make it counting time. Here is my code:

if(command === 'on') {
        const role = message.guild.roles.cache.find(role => role.name === '๐Ÿš€On Duty')
        message.author.send('You are on duty')
        message.member.roles.add(role)
        message.react('<:tick:902920026489749564>')
    } else if(command == 'off'){
    const role = message.guild.roles.cache.find(role => role.name === '๐Ÿš€On Duty')
    message.member.roles.remove(role)
    let seconds = Math.floor(message.member.roles.cache.has(role.id) / 1000);
    let minutes = Math.floor(message.member.roles.cache.has(role.id) / 60);
    let hours = Math.floor(message.member.roles.cache.has(role.id) / 60);
    let days = Math.floor(message.member.roles.cache.has(role.id) / 24);

    seconds %= 60;
    minutes %= 60;
    hours %= 24;

    const wc = new WebhookClient('MyWebhookId', 'myWebhookUrl')
    const log = new Discord.MessageEmbed()
    .setTitle('DUTY LOGS')
    .setDescription(`Username: <@${message.author.id}>\n`
    + `Days: **${days}**\n`
    + `Hours: **${hours}**\n`
    + `Minutes: **${minutes}**\n`
    + `Seconds: **${seconds}**`)
    .setTimestamp()
    .setColor('#fa0505')
    wc.send({
        username : message.author.tag,
        avatarURL : message.author.displayAvatarURL({ dynamic : true }),
        embeds : [log]
    })
    message.react('<:tick:902920026489749564>')
}

It gives me that answer when I type !off

about 4 years ago ยท Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!