Skip to content

Commit

Permalink
Stringify BigInts in request bodies (#1197)
Browse files Browse the repository at this point in the history
Base#toJSON still converts BigInts to strings to avoid returning a value
that can't be stringified.
  • Loading branch information
eritbh authored Jul 1, 2021
1 parent ea9d670 commit ed6b24c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 4 additions & 7 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,10 @@ class Client extends EventEmitter {
*/
editChannelPermission(channelID, overwriteID, allow, deny, type, reason) {
return this.requestHandler.request("PUT", Endpoints.CHANNEL_PERMISSION(channelID, overwriteID), true, {
allow: allow.toString(),
deny: deny.toString(),
type: type,
reason: reason
allow,
deny,
type,
reason
});
}

Expand Down Expand Up @@ -1272,9 +1272,6 @@ class Client extends EventEmitter {
* @returns {Promise<Role>}
*/
editRole(guildID, roleID, options, reason) {
if(typeof options.permissions === "bigint") {
options.permissions = options.permissions.toString();
}
options.reason = reason;
return this.requestHandler.request("PATCH", Endpoints.GUILD_ROLE(guildID, roleID), true, options).then((role) => new Role(role, this.guilds.get(guildID)));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/rest/RequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ class RequestHandler {
});
finalURL += "?" + qs.substring(1);
} else {
data = JSON.stringify(body);
// Replacer function serializes bigints to strings, the format Discord uses
data = JSON.stringify(body, (k, v) => typeof v === "bigint" ? v.toString() : v);
headers["Content-Type"] = "application/json";
}
}
Expand Down

0 comments on commit ed6b24c

Please sign in to comment.