Displaying all connected users Discord.js

流过昼夜 提交于 2019-12-06 00:49:12

Looking at https://discord.js.org/#/docs/main/master/class/Client?scrollTo=users, users is an associative array, not a function. Try:

Bot.on('ready', () => {
    setInterval (function (){
        var u, user;
        for(u in Bot.users){
           user = Bot.users[u];
           if(user instanceof Discord.User) console.log("["+u+"] "+user.username);
        }
    }, 10000);
});

EDIT: should now print out username and user id.

Bot.on("ready", function(){
    var Count;
    for(Count in Bot.users.array()){
       var User = Bot.users.array()[Count];
       console.log(User.username);
    }

})

I'm still quite new to javascript, and I've also had the same problem, so I tried solving it, took me forever to figure this out but I did it anyway, hope this helps!

I didn't add the setInterval thingy but you can add it in if you want. Basically i just added a .array and it worked.

It's going to display all users' username connected to your server, online or not :

Bot.on('ready', () => {
   setInterval (function (){
      for (user of Bot.users){
        console.log(user[1].username);
      }       
   }, 10000);});

Hey you better try this

code

    var guilds = client.guilds;
    console.log(guilds);

this returns a collecting which contain all the guilds which bot is connected and the guild contains its all members it gives lot of info see the cmd log

more refer here

what is the hell is guild use this link

https://discord.js.org/#/docs/main/stable/class/Guild

what the hell is collection look down

https://discord.js.org/#/docs/main/stable/class/Collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!