Added support for changing nicknames
This commit is contained in:
@@ -738,6 +738,13 @@ namespace Discord.API
|
||||
|
||||
return await Send<User>("PATCH", "users/@me", args).ConfigureAwait(false);
|
||||
}
|
||||
public async Task ModifyCurrentUserNick(ulong guildId, ModifyCurrentUserNickParams args)
|
||||
{
|
||||
if (args == null) throw new ArgumentNullException(nameof(args));
|
||||
if (args.Nickname == "") throw new ArgumentOutOfRangeException(nameof(args.Nickname));
|
||||
|
||||
await Send("PATCH", $"guilds/{guildId}/members/@me/nick", args).ConfigureAwait(false);
|
||||
}
|
||||
public async Task<Channel> CreateDMChannel(CreateDMChannelParams args)
|
||||
{
|
||||
if (args == null) throw new ArgumentNullException(nameof(args));
|
||||
|
||||
10
src/Discord.Net/API/Rest/ModifyCurrentUserNickParams.cs
Normal file
10
src/Discord.Net/API/Rest/ModifyCurrentUserNickParams.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
public class ModifyCurrentUserNickParams
|
||||
{
|
||||
[JsonProperty("nick")]
|
||||
public string Nickname { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@
|
||||
<Compile Include="API\Optional.cs" />
|
||||
<Compile Include="API\Rest\DeleteMessagesParam.cs" />
|
||||
<Compile Include="API\Rest\GetGuildMembersParams.cs" />
|
||||
<Compile Include="API\Rest\ModifyCurrentUserNickParams.cs" />
|
||||
<Compile Include="API\Rest\UploadFileParams.cs" />
|
||||
<Compile Include="API\Rest\GuildPruneParams.cs" />
|
||||
<Compile Include="API\Rest\CreateChannelInviteParams.cs" />
|
||||
|
||||
@@ -83,15 +83,29 @@ namespace Discord.Rest
|
||||
|
||||
var args = new ModifyGuildMemberParams();
|
||||
func(args);
|
||||
await Discord.BaseClient.ModifyGuildMember(Guild.Id, Id, args).ConfigureAwait(false);
|
||||
if (args.Deaf.IsSpecified)
|
||||
IsDeaf = args.Deaf;
|
||||
if (args.Mute.IsSpecified)
|
||||
IsMute = args.Mute;
|
||||
if (args.Nickname.IsSpecified)
|
||||
Nickname = args.Nickname;
|
||||
if (args.Roles.IsSpecified)
|
||||
_roles = args.Roles.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray();
|
||||
|
||||
bool isCurrentUser = IsCurrentUser;
|
||||
if (isCurrentUser && args.Nickname.IsSpecified)
|
||||
{
|
||||
var nickArgs = new ModifyCurrentUserNickParams
|
||||
{
|
||||
Nickname = args.Nickname.Value
|
||||
};
|
||||
await Discord.BaseClient.ModifyCurrentUserNick(Guild.Id, nickArgs).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (!isCurrentUser || args.Deaf.IsSpecified || args.Mute.IsSpecified || args.Roles.IsSpecified)
|
||||
{
|
||||
await Discord.BaseClient.ModifyGuildMember(Guild.Id, Id, args).ConfigureAwait(false);
|
||||
if (args.Deaf.IsSpecified)
|
||||
IsDeaf = args.Deaf;
|
||||
if (args.Mute.IsSpecified)
|
||||
IsMute = args.Mute;
|
||||
if (args.Nickname.IsSpecified)
|
||||
Nickname = args.Nickname;
|
||||
if (args.Roles.IsSpecified)
|
||||
_roles = args.Roles.Value.Select(x => Guild.GetRole(x)).Where(x => x != null).ToImmutableArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user