fix: Sending 2 requests instead of 1 to create a Guild role. (#1557)
The GuildHelper.CreateRoleAsync() was sending 2 requests to create a role. One to create the role, and one to modify the role that was created. This can be done in one request. So i have moved it to a single request to lower the amount of requests send to the api. This will also solve issue #1451.
This commit is contained in:
@@ -264,19 +264,18 @@ namespace Discord.Rest
|
||||
{
|
||||
if (name == null) throw new ArgumentNullException(paramName: nameof(name));
|
||||
|
||||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false);
|
||||
var role = RestRole.Create(client, guild, model);
|
||||
|
||||
await role.ModifyAsync(x =>
|
||||
var createGuildRoleParams = new API.Rest.CreateGuildRoleParams
|
||||
{
|
||||
x.Name = name;
|
||||
x.Permissions = (permissions ?? role.Permissions);
|
||||
x.Color = (color ?? Color.Default);
|
||||
x.Hoist = isHoisted;
|
||||
x.Mentionable = isMentionable;
|
||||
}, options).ConfigureAwait(false);
|
||||
Color = color?.RawValue ?? Optional.Create<uint>(),
|
||||
Hoist = isHoisted,
|
||||
Mentionable = isMentionable,
|
||||
Name = name,
|
||||
Permissions = permissions?.RawValue ?? Optional.Create<ulong>()
|
||||
};
|
||||
|
||||
return role;
|
||||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, createGuildRoleParams, options).ConfigureAwait(false);
|
||||
|
||||
return RestRole.Create(client, guild, model);
|
||||
}
|
||||
|
||||
//Users
|
||||
|
||||
Reference in New Issue
Block a user