Know which device it it
Is there a way to know in which device the user is? I have a few interactions that work 100% on the computer/web, but on mobile it gets laggy, so i want to have 2 response types, desktop and mobile, so the UI is more pleasant
5 Replies
- 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 staffI believe you can filter it by their presence.
Although may not work on members whose status is set to Invisible I think.
Presence has
desktop
, web
and mobile
properties I believe.you can check through
Presence.clientStatus.web|.desktop|.mobile
, I haven't tested this but I assume it works like this:
if the user is currently on desktop, then Presence.clientStatus.desktop
will contain data. Now lets say the user is online from a mobile device, then Presence.clientStatus.desktop
will be null but Presence.clientStatus.mobile
will contain a status
You can't really tell from which device the user is executing a command though, lets say the user is connected on both Desktop and Mobile, then both of those properties will have data, and you will not be able to tell
but you can exclusively send mobile responses if you check if ((!Presence.clientStatus.desktop && !Presence.clientStatus.web) && Presence.clientStatus.mobile)
if both of these conditions are true then its most likely that the user is only connected from mobile
that would be my suggestion, i really dont know if there is a better way, hope you can get a better answer
and remember what Toast said though, offline members will not have a presence, you will have to default to some kind of response. And yes you need the presence related intents enabledI cant find it thru the interaction context
because you have to get the member object from it first
<interaction>.member.presence
. keep in mind that you need to check if the interaction comes from a guild first
the also <member>.presence
can be null