GuildMember.from constructor

GuildMember.from({
  1. required dynamic user,
  2. required GuildRoleManager roles,
  3. required Guild guild,
  4. dynamic member,
  5. required VoiceManager voice,
})

Implementation

factory GuildMember.from({ required user, required GuildRoleManager roles, required Guild guild, dynamic member, required VoiceManager voice }) {
  MemberRoleManager memberRoleManager = MemberRoleManager(manager: roles, memberId: user.id);
  for (var element in (member['roles'] as List<dynamic>)) {
    Role? role = roles.cache.get(element);
    if (role != null) {
      memberRoleManager.cache.putIfAbsent(role.id, () => role);
    }
  }

  return GuildMember(
    user,
    member['nick'],
    member['avatar'] != null ? ImageFormater(member['avatar'], 'guilds/${guild.id}/users/${user.id}/avatars') : null,
    DateTime.parse(member['joined_at']),
    member['premium_since'] != null ? DateTime.parse(member['premium_since']) : null,
    member['permissions'],
    member['pending'] == true,
    member['communication_disabled_until'] != null ? DateTime.parse(member['communication_disabled_until']) : null,
    memberRoleManager,
    voice,
    guild
  );
}