Reputation: 21
I need some help: How am I able to create a embed that update itself every 2 seconds?
Info: The embed should include a countdown of 3 days. Every two seconds the embed should update itself and goes down to 00:00:00. I would like to use the following method to get the message and update itself:
bot.guilds.cache.get('').channels.cache.get('').messages.fetch('');
Im really new to discord.js development and need some help :D
Upvotes: 0
Views: 3229
Reputation: 23
Use markdown timestamp so you don't need to send requests from server every second.
Markup: <t:1655196925:R>
Check here: https://discord.com/developers/docs/reference#message-formatting-formats
Upvotes: 0
Reputation: 516
You can use the setInterval()
method to do this. What this does is run a block of code every ___ seconds. Using this, and a variable to store a Unix timestamp of when the timer will finish, we can update a message using the .edit()
method, so it shows how much time is left.
bot.on("ready", () => {
// other code
const message = bot.guilds.cache.get('').channels.cache.get('').messages.fetch('');
let timeLeft = INSERT TIMESTAMP HERE;
setInterval(() => {
timeLeft -= 2000;
message.edit(`There is ${timeLeft} time left!`):
}, 2000)
})
Upvotes: 1