updatePositions method

Future<List<Role>> updatePositions(
  1. Map<Snowflake, int> positions, {
  2. String? auditLogReason,
})

Update the positions of the roles in this guild.

Implementation

Future<List<Role>> updatePositions(Map<Snowflake, int> positions, {String? auditLogReason}) async {
  final route = HttpRoute()
    ..guilds(id: guildId.toString())
    ..roles();
  final request = BasicRequest(
    route,
    method: 'PATCH',
    auditLogReason: auditLogReason,
    body: jsonEncode(positions.entries.map((e) => {'id': e.key.toString(), 'position': e.value}).toList()),
  );

  final response = await client.httpHandler.executeSafe(request);
  final roles = parseMany(response.jsonBody as List, parse);

  roles.forEach(client.updateCacheWith);
  return roles;
}