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

154
Views
How do I make the bot send only 2 periods of time?

So simply i want to make my bot say : If the text have week specified, Then It'll send weeks and days remaining, If it has days, Then it'll send the days and hours remaining. Example:

Time remaining : 2 weeks, 3 days Time remaining : 1 day, 5 hours

The part of the code that has the weeks, Minutes, Hours, Seconds :

  let gwTime = ms(time);
  let timeRemain = gwTime 
  weeks = Math.floor((timeRemain / (24*60*60*1000))/7);
  weeksms = Math.floor((timeRemain % (24*60*60*1000))/7);
days = Math.floor(weeksms / (24*60*60*1000));
daysms = weeksms % (24*60*60*1000);
hours = Math.floor(daysms / (60*60*1000));
hoursms = timeRemain % (60*60*1000);
minutes = Math.floor(hoursms / (60*1000));
minutesms = timeRemain % (60*1000);
sec = Math.floor(minutesms / 1000);
// weeks = Math.floor(days / 7);
  let gwEmbed = new MessageEmbed()
  
    .setTitle(`${prize}`)

 //  .setDescription(`**Time Remaining**${weeks} weeks ${days} days
 //  .setDescription(`**Hosted By**`)
 // ${hours} hours ${minutes} minutes ${sec} seconds`)

    .addField('**Time Remaining: **', `${weeks} weeks ${days} days
 ${hours} hours ${minutes} minutes ${sec} seconds`, true)
  
    .addField('**Hosted By**', `<@965460337275064351>`, true)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I am not sure about what's the way for the message from the bot to be triggered so I assumed the bot will send a message that your code showed while executing a command.

You can use the if statement to determine whether the value is true or false, and check if it has an actual value either. To make it visualise, I will show it in code.

var No = 0;

if (!No) console.log('No Number')

In this situation, No is passing into the negative option of the conditional statement as the value of it is 0. Therefore, you will see 'No Number' in the console.

Back to your question, you can apply the if statements to check if there are weeks in remain or days either.

if (weeks) { // Have at least 1 week
    gwEmbed.addField('**Time Remaining: **', `${weeks} weeks ${days} days`, true)
} else if (days) { // Have at least 1 day
    gwEmbed.addField('**Time Remaining: **', `${days} days ${hours} hours`, true)
} else { // No week, No day

}

Besides your question, I doubt there are some bugs in the time converting code. I would recommend you use the variable separately. For instants, consider using timeRemain for every ms variable instead of using the upper one and making it chain.


For your references, here is the If statement Documentation:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else

about 4 years ago · Juan Pablo Isaza Report
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!