I have this code which works fine, I just need to check if a user has a role, it logs all the users, with their id, discriminator and username exc. I just can't get the roles. Can you guys please help?
client.on('ready', () => {
console.log(`logged in as ${client.user.username}`);
var Count;
for(Count in client.users.array()){
var User = client.users.array()[Count];
if(User.username == "someUsername"){
//User.sendMessage("you");
}
//User.checkRole("Admin");
}
}
checkRole()
function is something that I made up. I jsut need some help.
client.on('ready', () => {
console.log(`logged in as ${client.user.username}`);
var Count;
for(Count in client.users.array()){
var User = client.users.array()[Count];
if(User.hasRole("Admin")){
console.log(User.username);
}
}
})
To access roles you must approach it by guild, not user. (As mentioned by @Wright)
I'd do this using a map to save all the guild members, and then going through each member (that way when you come across one with a specific role name, you still have acess to the guildobject (as it is a guildmember object)
m = client.guilds.map(function (obj) {
return obj.members;
});
for (var i = 0; i < m.length; i++) {
console.log("\n\nNew Guild: ");
console.log(m[i].map(function (obj) {
return obj.guild.name + " , " + obj.user.username + " : " + obj._roles;
}).join('\n'));
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments