Checking if a user is mobiile

client.on('messageCreate', async (message) => {
// Check if the user is online and has presence data
if (message.author.presence && message.author.presence.clientStatus) {
const userIsOnMobile = message.author.presence.clientStatus.mobile;

if (userIsOnMobile) {
message.channel.send(`${message.author.username} is using Discord on mobile.`);
console.log('using')
} else {
message.channel.send(`${message.author.username} is not using Discord on mobile.`);
}
} else {
message.channel.send(`${message.author.username} is not currently online.`);
}
client.on('messageCreate', async (message) => {
// Check if the user is online and has presence data
if (message.author.presence && message.author.presence.clientStatus) {
const userIsOnMobile = message.author.presence.clientStatus.mobile;

if (userIsOnMobile) {
message.channel.send(`${message.author.username} is using Discord on mobile.`);
console.log('using')
} else {
message.channel.send(`${message.author.username} is not using Discord on mobile.`);
}
} else {
message.channel.send(`${message.author.username} is not currently online.`);
}
Ngl I tryed using gpt because I doubt anyone has ever gotten code for this lol
21 Replies
d.js toolkit
d.js toolkit7mo 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!
TÆMBØ
TÆMBØ7mo ago
Although you haven't actually expressed your issue, one main issue is regarding <Message>.author, which is a User object. Presences are only available on member data, so you want <Message>.member
Jordan
JordanOP7mo ago
issue is im not sure if what im trying is even possible lol
TÆMBØ
TÆMBØ7mo ago
If you have the right intents and code, yes, you can get the mobile status of a given member GuildMembers and GuildPresences intent will be necessary for this And as a side note, you'd be better off just getting help with d.js in this server. ChatGPT and any other AI has been proven to be quite unreliable both in d.js and outside of it
Jordan
JordanOP7mo ago
true ai is shit but its 3am and didnt think anyone would be online better question where can I find the docs for this
TÆMBØ
TÆMBØ7mo ago
This place has people from all over the globe, so there's bound to be a few people lurking at a given time
d.js docs
d.js docs7mo ago
:property: GuildMember#presence The presence of this guild member
Jordan
JordanOP7mo ago
if (!message.guild) return message.channel.send("This command can only be used in a guild.");

const member = message.guild.members.cache.get(message.author.id);
if (!member || !member.presence || !member.presence.clientStatus) {
return message.channel.send("Cannot determine user status.");
}

const userIsOnMobile = member.presence.clientStatus.mobile;
message.channel.send(`${member.displayName} is ${userIsOnMobile ? 'using' : 'not using'} Discord on mobile.`);
if (!message.guild) return message.channel.send("This command can only be used in a guild.");

const member = message.guild.members.cache.get(message.author.id);
if (!member || !member.presence || !member.presence.clientStatus) {
return message.channel.send("Cannot determine user status.");
}

const userIsOnMobile = member.presence.clientStatus.mobile;
message.channel.send(`${member.displayName} is ${userIsOnMobile ? 'using' : 'not using'} Discord on mobile.`);
can you give me a explanination of why I cant get the users device WAIT HOLD ON I MIGHT BE COOKING
TÆMBØ
TÆMBØ7mo ago
That’s a bit vague, what’s preventing you? What’s the code above you posted? Have you tested it? Does it work? Does it error?
Jordan
JordanOP7mo ago
it doesnt error wish code errored
TÆMBØ
TÆMBØ7mo ago
I’m also not sure why you’re traversing the member cache via the author’s ID when I mentioned you can simply do <Message>.member What unintended behavior is it giving?
Jordan
JordanOP7mo ago
cant find my shit cant tell if im using pc or phone
TÆMBØ
TÆMBØ7mo ago
Log some values, see what’s going on, do some debugging
Jordan
JordanOP7mo ago
"Cannot determine user status."
TÆMBØ
TÆMBØ7mo ago
Do you have both of these intents?
Jordan
JordanOP7mo ago
GuildPresences oh
TÆMBØ
TÆMBØ7mo ago
You should also be aware that GuildMembers are not cached by default, so if you haven’t received any other events that include that member, then it won’t be in the cache meaning you’ll have to fetch it first
Jordan
JordanOP7mo ago
const {Client, GatewayIntentBits, SlashCommandBuilder, EmbedBuilder, ActivityType, Partials, GuildMembers, GuildPresences}=require('discord.js');
TÆMBØ
TÆMBØ7mo ago
Those are not intents, those are imports
d.js docs
d.js docs7mo ago
:dtypes: v10: GatewayIntentBits - GuildPresences read more
Jordan
JordanOP7mo ago
ah now that you told me that I got a diff message 😄 GatewayIntentBits.GuildPresences, 🎊 W W
Want results from more Discord servers?
Add your server