User client(desktop client/browser/mobile)

How can I get the user's device
9 Replies
d.js toolkit
d.js toolkit6mo 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!
d.js docs
d.js docs6mo ago
:property: Presence#clientStatus discord.js@14.19.3 The devices this presence is on
Lyrian
Lyrian6mo ago
1. You need the privilege GUILD_PRESENCES 2. Example Code
const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences, // Required for presence updates
],
});

client.on('messageCreate', message => {
if (message.author.bot) return;

const user = message.member;
if (!user || !user.presence) {
return message.channel.send(`${message.author.username} is offline or I can't see their presence.`);
}

const clientStatus = user.presence.clientStatus;
const devices = [];

if (clientStatus.desktop) {
devices.push('Desktop');
}
if (clientStatus.mobile) {
devices.push('Mobile');
}
if (clientStatus.web) {
devices.push('Web');
}

if (devices.length > 0) {
message.channel.send(`${user.user.username} is currently active on: ${devices.join(', ')}`);
} else {
message.channel.send(`I can't determine ${user.user.username}'s device.`);
}
});

client.login('YOUR_SECRET_BOT_TOKEN');
const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences, // Required for presence updates
],
});

client.on('messageCreate', message => {
if (message.author.bot) return;

const user = message.member;
if (!user || !user.presence) {
return message.channel.send(`${message.author.username} is offline or I can't see their presence.`);
}

const clientStatus = user.presence.clientStatus;
const devices = [];

if (clientStatus.desktop) {
devices.push('Desktop');
}
if (clientStatus.mobile) {
devices.push('Mobile');
}
if (clientStatus.web) {
devices.push('Web');
}

if (devices.length > 0) {
message.channel.send(`${user.user.username} is currently active on: ${devices.join(', ')}`);
} else {
message.channel.send(`I can't determine ${user.user.username}'s device.`);
}
});

client.login('YOUR_SECRET_BOT_TOKEN');
Important Considerations * Offline Users: If a user is offline or has set their status to invisible, their presence will be null, and you won't be able to determine their device. * Multiple Devices: A user can be logged in on multiple devices at the same time. The clientStatus object will reflect all active sessions. * Intents are Crucial: Remember to enable the GUILD_PRESENCES intent for your bot. If you don't, presence will always be null for members.
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Lyrian
Lyrian6mo ago
1. What makes you say that the question was solved? Afaik the question isn't resolved. 2. It's partially AI-generated, but the answer is still correct. Why shouldn't I use AI?
ruyuol
ruyuol6mo ago
bro stop using ai pls
treble/luna
treble/luna6mo ago
#how-to-give-help first bullet point ai uses outdated data, gives incorrect answers most of the time and spoonfeeding isnt helping at all
ruyuol
ruyuol6mo ago
just dont, read how to give help channel
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?