Allow null value to reset IGuildUser nickname (#923)

* Added workaround for UserHelper#ModifyAsync that accepts null values as a way to reset user nicknames

* Update comments

* Update comment to use see tag
This commit is contained in:
Chris Johnston
2018-01-05 17:24:21 -08:00
committed by Christopher F
parent b30af57b7f
commit 227f61aa4e
2 changed files with 9 additions and 1 deletions

View File

@@ -34,7 +34,7 @@ namespace Discord
/// Should the user have a nickname set? /// Should the user have a nickname set?
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// To clear the user's nickname, this value can be set to null. /// To clear the user's nickname, this value can be set to <see langword="null" /> or <see cref="string.Empty" />.
/// </remarks> /// </remarks>
public Optional<string> Nickname { get; set; } public Optional<string> Nickname { get; set; }
/// <summary> /// <summary>

View File

@@ -48,6 +48,14 @@ namespace Discord.Rest
else if (args.RoleIds.IsSpecified) else if (args.RoleIds.IsSpecified)
apiArgs.RoleIds = args.RoleIds.Value.ToArray(); apiArgs.RoleIds = args.RoleIds.Value.ToArray();
/*
* Ensure that the nick passed in the params of the request is not null.
* string.Empty ("") is the only way to reset the user nick in the API,
* a value of null does not. This is a workaround.
*/
if (apiArgs.Nickname.IsSpecified && apiArgs.Nickname.Value == null)
apiArgs.Nickname = new Optional<string>(string.Empty);
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false); await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false);
return args; return args;
} }