Presence Activity with dynamic data

Hi, I've seen that with some games when someone is queuing for the matchmaking, it shows a timer that is up to date at the second. For internal use in a server, I want to make something similar with a bot where it would show the current time in 4 specific timezones. How would one go about a task like this? Obviously, one way would be with a setInterval running every second but I'm wondering if there's a better way
16 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
0xSynon
0xSynonOP15mo ago
Discord version: [email protected] Node version: v18.16.0
souji
souji15mo ago
if you want it to show the delta or time for anyone, based on their system time, you can use the timestamp styles native to discord
d.js docs
d.js docs15mo ago
method time Formats a date into a short date-time string.
souji
souji15mo ago
if you want to show the time in these specific timezones for a reason, packages like https://moment.github.io/luxon can help with that - which then makes the question better suited for #other-js-ts instead, since it has nothing to do with discord.js anymore
d.js docs
d.js docs15mo ago
mdn Date.prototype.toLocaleString() The toLocaleString() method of Date instances returns a string with a language-sensitive representation of this date. In implementations with Intl.DateTimeFormat API support, this method simply calls Intl.DateTimeFormat.
souji
souji15mo ago
might also be enough, depending on your formatting needs
0xSynon
0xSynonOP15mo ago
yeah my main question is should I use setInterval to update the presence each second or is there a way to leverage timers like how video games do when you're in a matchmaking my question is still in regards to Discord API (and more specifically, the high level API from DiscordJS) but if the answer is setInterval, I'm fine with that too, just wondering if there are API limits I should be aware of
souji
souji15mo ago
as said, if you want it to adapt to the viewer's timezone, this is the way to go
monbrey
monbrey15mo ago
I'm pretty certain you cant update presence every second, so this would not be the right approach
0xSynon
0xSynonOP15mo ago
I don't want it to adapt to the viewer's timezone I want the bot to show, as its activity, the time in a specific timezone without adapting to any user's timezone discord's API supports Rich presence with timers, I know how I could replicate it with setTimeout but it sounds so silly, I'm thinking there has to be a better way, that's what I'm asking here
0xSynon
0xSynonOP15mo ago
How does League of Legends do it?
0xSynon
0xSynonOP15mo ago
Surely if you can show time elapsed at the second, you can show a clock You definitely can though, just saying. This guy makes 10 updates per second https://github.com/discord/discord-api-docs/issues/668 if my only way to achieve that is by setting a startTimestamp and it would calculate the elapsed time, i have no problem setting that to whatever timestamp represends midnight in the timzone i want to show my question is how to do this with DiscordJS
0xSynon
0xSynonOP15mo ago
it's definitely supported by discord API
No description
0xSynon
0xSynonOP15mo ago
on djs documentation, the only thing I find about Rich Presence are the RichPresenceAssets and it doesn't seem to include the keys I'm interested in https://discord.js.org/docs/packages/discord.js/14.14.1/RichPresenceAssets:Class does that make sense?
monbrey
monbrey15mo ago
I can say with certainty that the limit for presence updates used to be 5/min, or about once every 12 seconds
it should be 1/15 but is currently 5/60 or something like that, so we'll fix both that and the empty presence thing. Thanks again for the report!
Yeah, they're saying the limit is once per 15 seconds That issue specifically says that the guy trying to make 10 updates a second causes a bug - never that you should be able to make that many updates RichPresence is largely unrelated to discord.js though - RPC is a local client connectivity thing Its not a bot feature

Did you find this page helpful?