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
DT
d.js toolkit16d 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
TÆMBØ16d 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
J
Jordan16d ago
issue is im not sure if what im trying is even possible lol
T
TÆMBØ16d 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
J
Jordan16d 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
TÆMBØ16d ago
This place has people from all over the globe, so there's bound to be a few people lurking at a given time
DD
d.js docs16d ago
:property: GuildMember#presence The presence of this guild member
J
Jordan16d 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
TÆMBØ16d 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?
J
Jordan16d ago
it doesnt error wish code errored
T
TÆMBØ16d 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?
J
Jordan16d ago
cant find my shit cant tell if im using pc or phone
T
TÆMBØ16d ago
Log some values, see what’s going on, do some debugging
J
Jordan16d ago
"Cannot determine user status."
T
TÆMBØ16d ago
Do you have both of these intents?
J
Jordan16d ago
GuildPresences oh
T
TÆMBØ16d 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
J
Jordan16d ago
const {Client, GatewayIntentBits, SlashCommandBuilder, EmbedBuilder, ActivityType, Partials, GuildMembers, GuildPresences}=require('discord.js');
T
TÆMBØ16d ago
Those are not intents, those are imports
DD
d.js docs16d ago
:dtypes: v10: GatewayIntentBits - GuildPresences read more
J
Jordan16d 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
More Posts
Sharding QuestionsHello, As my bot is nearly reaching the 2k servers. I need to prepare it to sharding but I have soRepeating interactionIs there a way to use the 'interaction.update' multiple times? So i can make like one button after aWhat Discord.js features have the potential to hit the limit/go over the set Discord API limits?Where can I even find Discord's API limits? I just want to make sure that what I am doing with my boError when i do npm install discord.jsi don’t know how to fix this at all and i’m beyond confused i’ve tried so many times i am useing VisSimple question, how can I check if an incoming message is *specifically* a slash command?How can I check to see if an incoming message (messageCreate) is a slash command? Sometimes a typo cdiscord voice enginehello im just asking if someone got an alternative discord voice engine that work on windowsDeleting Ephemeral MessagesIs there any sort of way to reply to an interaction privately and then delete the reply?Button Automatically PressingHello! Im currently working on a bot using oauth2. Im in the middle of rewriting how i handle refresBot joins the vc but audio doesn't playyes the path is correct. ```js var { voice } = message.member if(!voice.channelId) return mCommand handler changeWould it be possible (is there an example) of a command handler, that looks into a folder with all oMessage listener only on certain channels?Hey there! So I have this: ```js module.exports = { name: Events.MessageCreate, async execuApplication did not Respond!I am hosting a bot that can send image with ping like quality control but everytime i run a code theOpening handshake timeoutHi, I'm testing my bot and i make reboots often. I have and `Opening handshake has timed out` when help me to resolvei created a self role select menu . when i call the setup command and interact with the channel seleFetch messages from multiple channelsHeya, I need a solution to find active users in a guild, so the base idea is like a command that defRebuild Bot Guide IDSo, at the moment my config consists of `"guildId": "xxxxxxxxxxxxxxxx",` which is the guideID. IdeferReply without messagehow to turn off the message in inter.deferReply (not ephemeral: true)my code is not working!i can't get multiple roles uisng addroleopts```.addRoleOption(option => option .setName('role') How to register commands using .set() ( ill explain in thread )hello