6

I wrote a little bot and need the status(Online,Offline,Idle) of all users on the server. I found https://discord.js.org/#/docs/main/master/class/Client?scrollTo=users

bot.on('ready', function() { console.log(bot.users); });

This show all users with:

'352....128': User { username: 'NAME', id: '352....128', discriminator: '5000' avatar: null, bot: false },

So there is no status. The Bot have no access for this? In embed.js I can read the status of all online and idle users (offline users are not listed): https://discordapp.com/api/guilds/SERVERID/embed.json

{"username": "NAME", "status": "online", "nick": "NICK", "avatar_url": "...", "avatar": "...", "discriminator": "5000", "id": "..."}

Is embed.json the only way to get the status of all online and idle users? So I need to install this package? https://www.npmjs.com/package/jsonfile and read this file?

1
  • Please let me know if it works
    – C.Unbay
    Sep 6, 2017 at 16:59

4 Answers 4

13

You can find it here: https://discord.js.org/#/docs/main/stable/typedef/PresenceStatus

You can either use:

user.presence.status

or:

member.user.presence.status

It's returns "online", "idle", "dnd" or "offline"

0
2

Or even simpler :

.addField('Status', message.author.presence.status)
0

You need to get your bot to set the status by itself, for example

const Discord = require("discord.js");
const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
  client.user.setStatus("online");
});        


client.on("disconnected", () => {
    client.user.setStatus("offline");
    console.log(client.user); //returns the current user
});

console.log(client.users); //returns all users

To see all client events, please see here

Update

client.on("message", function(msg){
    if(client.user.isAdmin){ //checking as an admin for example
      if(msg.content == "-showUsers"){
         client.deleteMessage(msg, callBackFunc);
         console.log(bot.users);
      }
    }
})
2
  • Thanks! What is with users that are already on server? You only catch new connections and disconnection and what is with "idle" status? :)
    – user706420
    Sep 6, 2017 at 16:10
  • I have made a small piece of code as an update, I don't know if it'd work, but it's basically typing a command in the channel to retrieve all users :) Please let me know if it works. I am not too sure. @user706420
    – C.Unbay
    Sep 6, 2017 at 16:35
-7
var KlausAlge = "Klaus Alge"

for (KlausAlge in map) return true
for (!KlausAlge in map) return false
4
  • 5
    Can you please add an explanation as to how any why your answer is a good solution and how it works as per stackoverflow.com/help/how-to-answer Jun 10, 2020 at 16:16
  • Welcome to Stack Overflow! While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply. From Review Jun 11, 2020 at 4:13
  • Enter an explanation to how your code should work. The code is not obviouse. It seems it doesn't solve the question, so please edit the question and write an explanation of ho your code works
    – Lixt
    Aug 2, 2022 at 11:19
  • Trolling be like
    – Coder2195
    Feb 28, 2023 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.