What steps should I take to incorporate a timer into my bot similar to the timer used by other giveaway bots

I am looking to add a timer to my bot giveaway embed message that continues to update itself even when the bot is offline, without showing that the message was edited.

Here's what I currently have in my embed:

   const embed = new MessageEmbed();
   embed.setAuthor({
        name: `${message.guild.name} GiveAways!`,
        iconURL: `${message.guild.iconURL({ dynamic: true })}`
   });
   embed.setThumbnail(`${message.guild.iconURL({ dynamic: true })}`);
   embed.setTitle(`${title.toUpperCase()}`);
   embed.setColor("BLURPLE");
   embed.setDescription(
      `
      **React With 🎉 To Enter!**
      **Ends In: ${time} ${}!**
      **Hosted By: ${message.author}!**
      `
   );
   embed.setFooter({
       text: `${winnerCount.toString().slice(0, -1)} Winners | Ends`
   });
   embed.setTimestamp(Date.now() + ms(duration));

   const sentGiveaway = await channel.send({
      content: "||@everyone|| **🥳   GIVEAWAY   🥳**",
      embeds: [embed]
   });
   sentGiveaway.react("🎉");

title - Sets the title for the giveaway. time - Converts the user-entered duration into a full name (e.g. 4d => 4 Days). winnerCount - Determines how many winners there will be. duration - Takes the duration argument from the user. Date.now + ms(duration) - Provides the exact end time of the giveaway.

My current embed setup includes details about the duration and other information, but the embed.setTimestamp() function only indicates the end time of the giveaway. However, I want an automatic time update feature next to the variable time in the description that updates even when the bot is offline. I've seen other bots do this, but I am unsure how to implement it.

The image linked here showcases the type of time update feature I'm referring to, where the timer continues updating even when the bot is offline.

Answer â„–1

To learn more about working with unix timestamps, click here.

Unix timestamps utilize seconds instead of milliseconds, so remember to divide by 1000 and use Math.floor() when converting from milliseconds.

Here is an example:

const timestamp = new Date().getTime() + 600000 // (in 10 minutes)
const timestampInSecs = Math.floor(timestamp / 1000); // Division needed for conversion

// Select the formatting option that suits your needs - GiveawayBot prefers R
const timestampString = `<t:${timestampInSecs}:R>`;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

Is it feasible to duplicate the node_modules directory instead of reinstalling it each time for create-react-app?

As a newcomer to React, I am in the process of creating simple applications by following tutorials to become more acquainted with React. However, it is frustrating that every time I create a new react app using create-react-app, I have to download the enti ...

`Angular Image Upload: A Comprehensive Guide`

I'm currently facing a challenge while attempting to upload an image using Angular to a Google storage bucket. Interestingly, everything works perfectly with Postman, but I've hit a roadblock with Angular Typescript. Does anyone have any suggesti ...

The Express Json Validator Middleware will return a 404 error code if there are no errors in the JSON body

I am struggling to have this application return a 200 status code and an empty json response when there are no validation errors in the json request body. However, the app always returns a 404 error. The application utilizes expressjs along with the expre ...

Create a captivating sliding effect on Windows 8 using a combination of CSS and JavaScript

I believe that using css3 alone can achieve this effect, but I'm struggling with understanding properties like 'ease' in css3. This is the progress I have made so far: http://jsfiddle.net/kwgy9/1/ The word 'nike' should slide to ...

Jake battles it out with Cake in the Node.js application world?

After conducting some research, I have not found any convincing reasons to choose Jake over Cake for my Node.js build process (mainly just compiling *.coffee to *.js in the correct directories). Can anyone provide a few quick bullet points outlining why on ...

Passport causing Node.JS application to crash

After developing my app to work locally, I made all necessary adjustments for Heroku. Procfile web: node app.js package.json { "name": "HipsterMatch", "version": "0.0.1", "private": true, "scripts": { "start": "nodemon app.js" }, "depen ...

When running npm install, the dist folder is not automatically generated

I found a helpful tutorial at this link for creating a Grafana plugin. However, when I tried copying the code from this link to my test server (without the dist/ folder) and ran npm install, it did not generate a new dist/ folder but created a node_module ...

Filtering a list with Vue.js using an array of checkboxes

Currently, I am exploring ways to filter a v-for list using a checkbox model array with multiple checkboxes selected. Most examples I have come across only demonstrate filtering one checkbox at a time. In the demo here, you can see checkboxes 1-3 and a lis ...

Loss of image quality when utilizing Next/Image in NEXT JS

I am currently developing a web application using Next.js 13, and I recently noticed a decrease in the quality of my images. I'm not sure what went wrong or what I may have missed. Upon inspecting the HTML element on the browser, I found this code: & ...

Using VueJS: Passing a variable with interpolation as a parameter

Is there a way to pass the index of the v-for loop as a parameter in my removeTask function? I'm looking for suggestions on how to achieve this. <ol class="list-group"> <li v-for="task in tasks" class="list-group-item"> ...

Fetching Data Using Cross-Domain Ajax Request

Seeking assistance with a cross-domain Get request via Ajax. The code for my ajax request is as follows: var currency_path = "http://forex.cbm.gov.mm/api/latest"; $.ajax({ url: currency_path, crossDomain:true, type:"GET", dataTyp ...

What is the best way to increase the value of a variable using jQuery?

As I work on adding dates to a slider, I find myself needing to increment the values with each click. Initially, I start with the year - 2. $('#adddates').click(function() { var year = 2; $("#slider").dateRangeSlider({ bounds: { ...

Webstorm encounters difficulties compiling Sass

While attempting to utilize Sass in the Webstorm IDE, I noticed that it is defaulting to Ruby 1.8 (OS Default) instead of my preferred RVM Ruby Version (1.9.x). To address this issue, I tried setting the path for Sass in the Watcher-Configuration: PATH=$ ...

Utilizing postBack to send chatbot responses with BotFramework v4 and Node.js

I'm looking to send a postBack text message to my bot, but I need help with the correct syntax. Here's the code snippet: if (postback.payload == "WHAT_IS_MENTAL_HEALTH") { await turnContext.sendActivity("TO-DO: Forward on 'What Is Me ...

Challenge in resolving a promise returned by the find() function in mongodb/monk

I've encountered an issue where the simple mongodb/monk find() method isn't working for me. I am aware that find() returns a promise and none of the three ways to resolve it seem to be successful. Can someone point out what mistake I might be mak ...

What is the best way to switch the site header in JavaScript or jQuery?

I have created a Bootstrap menu design and I am looking to add a sliding functionality to it. My goal is to hide the menu when scrolling down and display it when scrolling up (slide-down / slide-up). For implementing this feature, I plan to utilize jQuery ...

It seems that there is a null value being returned in the midst of the

I have developed a model using express. While setting this in one function, it returns null in another function, forcing me to use return. What is the proper method to handle this situation? const Seat = function(seat) { this.seat = seat.seat; this. ...

Having trouble with my nodejs Express regex path. It works fine in my test environment but not in my actual code. Any suggestions on what

Looking for a simple filter in nodejs express routing path. The parameter must be either word1 or word2. Tested using: Using the expression: test/:gender(\b(word1|word2)\b) The path tested was: test/word2 Everything seems to work fine as "The ...

Does the package.json file have a key for specifying the directory of static assets?

It seems that there are a few unconventional package.json keys floating around, such as unpkg or jsnext. I've even heard about one for style. Is there any sort of informal standard in place for determining where static assets (like images and fonts) ...