Display Relative Time in a Discord Embedded Message

Lucas Minter
InstructorLucas Minter
Share this video with your friends

Social Share Links

Send Tweet

In this lesson, you will be learning how to display relative time in a Discord embedded message using the Unix timestamp.

We'll be adding a countdown timer to an embedded message to show the time remaining until submissions to a book-club close.

By the end of this lesson, you will have the ability to convert hours into seconds, add it to the current time in the Unix timestamp, and create a variable to store the wait time in seconds to display the short date time and relative time in Discord.

[0:00] Instructor: Our message is looking much nicer, but there's one thing I want to do to it. Down here in our submissions, this hours variable is hard-coded. That means our users are going to have to figure out the exact time it ends themselves and it's not going to be immediately apparent.

[0:21] We can display the relative time to our users using the Unix timestamp. Discord has a couple of different ways that we can show the time to our users. I'm going to be using the short date time and the relative time. The short date will be in our name, just to show the exact time that it ends.

[0:41] Then the relative time will be our countdown timer for when the submissions close. The first thing we need to do is convert our hours into seconds by multiplying our hours by 3,600 and set that to a variable. Set that equal to hours times 3,600.

[1:06] Now, we need to add that to the current time in the Unix timestamp to get when submissions will be closed. We'll create a variable called time expires at, set that to new dates, get the time, divide that by 1,000.

[1:29] Now, we need this to be a round number. Put that in parentheses and do math.floor. Then add on our wait time in seconds. Now, down in our fields, we can place this hours with time expires at, we'll add in the Syntax for the short date time.

[1:49] We'll delete hours because that won't be necessary anymore. We'll also delete in because that also won't be necessary. We'll add in the Syntax for the relative time. It's saved, head back over to Discord, run our Command again.

[2:15] Hit enter. There you go, you can see the short time and date. You can also see the relative time down here. Now, I'll wait a minute so that you can see that it actually is the relative time counting down. Now, you can see, time runs out in 59 minutes.