The Client::update_role_positions function always errors, as discords API expects a different format from what it provides.
The error:
Response error: status code 400, error: {"message": "Invalid Form Body", "code": 50035, "errors": {"0": {"_errors": [{"code": "DICT_TYPE_CONVERT", "message": "Only dictionaries may be used in a DictType"}]}, "1": {"_errors": [{"code": "DICT_TYPE_CONVERT", "message": "Only dictionaries may be used in a DictType"}]}}}
The issue is in twilight-http/src/request/guild/role/update_role_positions.rs;
Where self.roles is &[(Id<RoleMarker>, u64)], which will be serialized by serde_json as a 2d array, like [[id1, pos1], [id2, pos2]].
By Discord API docs for Modify Guild Role Positions, the API expects an array of dictionaries, each with an id and position field; such as [{"id":id1,"position":pos1},{"id":id2,"position":pos2}].
My quick but inefficient patch was to remap the format and allocate a Vec:
But it would probably be better to change the API to take in a list of RolePositions directly
to avoid the internal reallocation. (Similar to the API used for update_guild_channel_positions,
see #2327.)
The
Client::update_role_positions
function always errors, as discords API expects a different format from what it provides. The error:The issue is in
twilight-http/src/request/guild/role/update_role_positions.rs
;Where
self.roles
is&[(Id<RoleMarker>, u64)]
, which will be serialized byserde_json
as a 2d array, like[[id1, pos1], [id2, pos2]]
.By Discord API docs for Modify Guild Role Positions, the API expects an array of dictionaries, each with an
id
andposition
field; such as[{"id":id1,"position":pos1},{"id":id2,"position":pos2}]
.My quick but inefficient patch was to remap the format and allocate a Vec:
But it would probably be better to change the API to take in a list of
RolePosition
s directly to avoid the internal reallocation. (Similar to the API used forupdate_guild_channel_positions
, see #2327.)