From 227f61aa4e05affb0eb76aa3ab2ebd3bc2c0e30f Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Fri, 5 Jan 2018 17:24:21 -0800 Subject: [PATCH] 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 --- .../Entities/Users/GuildUserProperties.cs | 2 +- src/Discord.Net.Rest/Entities/Users/UserHelper.cs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs b/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs index 33b311604..1c5e5482c 100644 --- a/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs +++ b/src/Discord.Net.Core/Entities/Users/GuildUserProperties.cs @@ -34,7 +34,7 @@ namespace Discord /// Should the user have a nickname set? /// /// - /// 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 or . /// public Optional Nickname { get; set; } /// diff --git a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs index 562cfaae8..dfb81ff2c 100644 --- a/src/Discord.Net.Rest/Entities/Users/UserHelper.cs +++ b/src/Discord.Net.Rest/Entities/Users/UserHelper.cs @@ -48,6 +48,14 @@ namespace Discord.Rest 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.Empty); + await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, apiArgs, options).ConfigureAwait(false); return args; }