Discord-Net-Labs / Discord.Net-Labs

An experimental fork of Discord.Net that implements the newest discord features for testing and development to eventually get merged into Discord.Net
https://labs.discordnet.dev
MIT License
156 stars 42 forks source link

`SocketGuild.Users` only gets users that are chatting #275

Closed kram-tm closed 2 years ago

kram-tm commented 2 years ago

2BDBF072-B486-4912-978B-0A69AE825C8C

Guild.Users only gets users that have sent at least one message while the bot was online. This doesn't seem to be a problem with Discord.Net. Code:

[Command("getmembers")]
public async Task GetMembers()
{
  List<string> users = new List<string>();
  foreach(SocketGuildUser user in Context.Guild.Users)
  {
    users.Add(user.Username);
  }
  await ReplyAsync(String.Join(", ",users));
}

I originally wanted to get every user who has the specified role, but I got the same results. Is there an extra step I'm missing or am I just dumb?

quinchs commented 2 years ago

The reason for this is that socket related entities are cached, if you want to get all the users you need to download them from the gateway. One simple way of doing this is setting AlwaysDownloadUsers to true in your socket config

kram-tm commented 2 years ago

Works. Thank you!