Skip to content

Commit

Permalink
Allow null value to reset IGuildUser nickname (#923)
Browse files Browse the repository at this point in the history
* Added workaround for UserHelper#ModifyAsync that accepts null values as a way to reset user nicknames

* Update comments

* Update comment to use see tag
  • Loading branch information
Chris-Johnston authored and foxbot committed Jan 6, 2018
1 parent b30af57 commit 227f61a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs
Expand Up @@ -34,7 +34,7 @@ public class GuildUserProperties
/// Should the user have a nickname set?
/// </summary>
/// <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>
public Optional<string> Nickname { get; set; }
/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/Discord.Net.Rest/Entities/Users/UserHelper.cs
Expand Up @@ -48,6 +48,14 @@ internal static class UserHelper
else if (args.RoleIds.IsSpecified)
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);
return args;
}
Expand Down

0 comments on commit 227f61a

Please sign in to comment.