listGuildMembers method
Stream all members in a guild that match query
or userIds
.
If neither is provided, all members in the guild are returned.
Implementation
Stream<Member> listGuildMembers(
Snowflake guildId, {
String? query,
int? limit,
List<Snowflake>? userIds,
bool? includePresences,
String? nonce,
}) async* {
if (userIds == null) {
query ??= '';
}
limit ??= 0;
nonce ??= '${Snowflake.now().value.toRadixString(36)}${guildId.value.toRadixString(36)}';
final shard = shardFor(guildId);
shard.add(Send(opcode: Opcode.requestGuildMembers, data: {
'guild_id': guildId.toString(),
if (query != null) 'query': query,
'limit': limit,
if (includePresences != null) 'presences': includePresences,
if (userIds != null) 'user_ids': userIds.map((e) => e.toString()).toList(),
'nonce': nonce,
}));
int chunksReceived = 0;
await for (final event in events) {
if (event is! GuildMembersChunkEvent || event.nonce != nonce) {
continue;
}
yield* Stream.fromIterable(event.members);
chunksReceived++;
if (chunksReceived == event.chunkCount) {
break;
}
}
}