#Can't edit embed after 1 hour?

39 messages · Page 1 of 1 (latest)

indigo kiln
#

Currently I have slash command that returns an embed and it has a countdown timer in the footer. The countdown time is provided by the parameters in the slash command.

The issue that I am facing right now is, the countdown is working perfectly fine up until one hour since the command has been kicked off. Once it goes past this hour, the embed is extremely sluggish and will not update the embed. It will start out slow and then eventually just stop working. I am not receiving any errors in my console either. Everything still seems to be working in the backend though as I have been console logging every time it should be updating but the UI does not want to update.

discod.js version - 14.6.0
node.js version - 19.0.1
Code - https://paste.ofcode.org/zqsuQ6U66s3kUa6fXWmatL

In the code above, the embed updates every second but I have also tried to update it every minute. This does not seem to work either.

cyan ledge
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

marsh hull
#

You’re editing an embed every second…??

#

You’re probably encountering rate limits on editing as every second is very very high

indigo kiln
#

As I said above, I did try updating every mintue as well but that does not seem to work either

marsh hull
#

Listen to the rate limit event

#

That’ll give you more info

#

client.rest.on(“rateLimited”, …

indigo kiln
#

Correct me if I am mistaken, isn't the rate limit 50 requests per second to discords API?

marsh hull
#

No idea as rate limits are sliding and dynamic

indigo kiln
#

From the discord.js docs:

marsh hull
#

50 per second wouldn’t also mean edit the embed 50 times a second

indigo kiln
#

Right but if its updating every second, wouldn't that just be 1 per second?

marsh hull
#

Which is extremely high

night arrowBOT
#

Ratelimits are dynamically assigned by the API based on current load and may change at any point.
• The scale from okay to API-spam is sliding and depends heavily on the action you are taking
• Rainbow roles, clock and counter channels, and DM'ing advertisements to all members are all examples of things that are not okay

marsh hull
#

Djs handles rate limits for you, which is probably why it feels “sluggish” because it’s just stopping you from doing that action

indigo kiln
#

Got it okay, but as I said above - this still does not seem to work even if its updating every minute compared to every second. Is updating every minute high as well?

marsh hull
#

Not really no, but you could be editing 10 others at the same rate which could cause it. As I said before, listening to the rate limit event may help

near bison
#

having timers with constant status editing is very much not what you should be doing in the first place. use a timestamp, have a command for checking remaining time, those don't require endless spamming of the api for unspecified amounts of time

#

and whatever is happening after that 1 hour is most likely there to combat this very thing

#

due to how discord handles storing of messages at various stages (ever noticed that bulkDelete is limited to 2 week old messages?)

indigo kiln
near bison
#

it does

#

it still is quite dumb, timestamp can do this just fine for up to an hour and requires exactly 0 edits

#

1/h if you want to move it 1h ahead every hour

indigo kiln
#

So from what I am seeing is, the best way to implement this would just be to remove it?

near bison
#

countdown on its own isn't a bad idea if you need it or use it. it's just that this specific way of implementing it is very much not what should happen

#

discord added timestamps - you can use a relative timestamp that will display natively with remaining time and keeps track on its own

#

for anything longer-running, you could rename the feature into reminders. and reminders are usually persisted in database since they have high potential of having end times very far in the future

#

and then just handle them like reminders - store in db, every once in a while query your db to see what's expiring soon, and then wait out the last couple of minutes with a setTimeout.

in any case, just returning a timestamp of when it ends, and eventually providing a way to re-send that timestamp would probably be the best way to implement this

indigo kiln
near bison
#

the timestamp is just <t:unixTimestampInSeconds:R>, and discord client displays that like <t:1672278532:R>, same way it converts <:emoji:id> into emote or @near bison into a mention

#

but the timestamp only displays whatever time is set in it, it doesn't edit itself

indigo kiln
#

Got it okay so I could do <t:1672279999:R> and then just send an update once it is finished to say "this has ended"

#

Well thats pretty neat.. I didn't know you could do that

#

How would I go about putting that into an embed though?

near bison
#

same way you would put it in the message

#

but i'm not sure if it will resolve in any place in the embed, things like emotes or mentions or masked links tend to not resolve in some parts