diff --git a/src/Discord.Net/DiscordClient.Members.cs b/src/Discord.Net/DiscordClient.Members.cs index 980841bb3..f92591a00 100644 --- a/src/Discord.Net/DiscordClient.Members.cs +++ b/src/Discord.Net/DiscordClient.Members.cs @@ -135,8 +135,8 @@ namespace Discord public Task EditMember(string serverId, string userId, bool? mute = null, bool? deaf = null, IEnumerable roles = null) { CheckReady(); - if (serverId == null) throw new NullReferenceException(nameof(serverId)); - if (userId == null) throw new NullReferenceException(nameof(userId)); + if (serverId == null) throw new ArgumentNullException(nameof(serverId)); + if (userId == null) throw new ArgumentNullException(nameof(userId)); var newRoles = CollectionHelper.FlattenRoles(roles); return _api.EditMember(serverId, userId, mute: mute, deaf: deaf, roles: newRoles); diff --git a/src/Discord.Net/DiscordClient.Messages.cs b/src/Discord.Net/DiscordClient.Messages.cs index 59e4301e4..2e9263b5b 100644 --- a/src/Discord.Net/DiscordClient.Messages.cs +++ b/src/Discord.Net/DiscordClient.Messages.cs @@ -228,8 +228,8 @@ namespace Discord public async Task DownloadMessages(string channelId, int count, string beforeMessageId = null, bool cache = true) { CheckReady(); - if (channelId == null) throw new NullReferenceException(nameof(channelId)); - if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); + if (channelId == null) throw new ArgumentNullException(nameof(channelId)); + if (count < 0) throw new ArgumentNullException(nameof(count)); if (count == 0) return new Message[0]; Channel channel = _channels[channelId]; diff --git a/src/Discord.Net/DiscordClient.Permissions.cs b/src/Discord.Net/DiscordClient.Permissions.cs index e6b46b8ac..9727c04df 100644 --- a/src/Discord.Net/DiscordClient.Permissions.cs +++ b/src/Discord.Net/DiscordClient.Permissions.cs @@ -33,9 +33,9 @@ namespace Discord private async Task SetChannelPermissions(Channel channel, string targetId, string targetType, PackedChannelPermissions allow = null, PackedChannelPermissions deny = null) { CheckReady(); - if (channel == null) throw new NullReferenceException(nameof(channel)); - if (targetId == null) throw new NullReferenceException(nameof(targetId)); - if (targetType == null) throw new NullReferenceException(nameof(targetType)); + if (channel == null) throw new ArgumentNullException(nameof(channel)); + if (targetId == null) throw new ArgumentNullException(nameof(targetId)); + if (targetType == null) throw new ArgumentNullException(nameof(targetType)); uint allowValue = allow?.RawValue ?? 0; uint denyValue = deny?.RawValue ?? 0; @@ -108,9 +108,9 @@ namespace Discord private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, string idType) { CheckReady(); - if (channel == null) throw new NullReferenceException(nameof(channel)); - if (userOrRoleId == null) throw new NullReferenceException(nameof(userOrRoleId)); - if (idType == null) throw new NullReferenceException(nameof(idType)); + if (channel == null) throw new ArgumentNullException(nameof(channel)); + if (userOrRoleId == null) throw new ArgumentNullException(nameof(userOrRoleId)); + if (idType == null) throw new ArgumentNullException(nameof(idType)); try { diff --git a/src/Discord.Net/DiscordClient.Roles.cs b/src/Discord.Net/DiscordClient.Roles.cs index 24e316401..7065b02c9 100644 --- a/src/Discord.Net/DiscordClient.Roles.cs +++ b/src/Discord.Net/DiscordClient.Roles.cs @@ -80,7 +80,7 @@ namespace Discord public async Task CreateRole(string serverId, string name) { CheckReady(); - if (serverId == null) throw new NullReferenceException(nameof(serverId)); + if (serverId == null) throw new ArgumentNullException(nameof(serverId)); var response = await _api.CreateRole(serverId).ConfigureAwait(false); var role = _roles.GetOrAdd(response.Id, serverId); @@ -91,20 +91,19 @@ namespace Discord return role; } - public Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null) - => EditRole(role.ServerId, role.Id, name: name, permissions: permissions, color: color, hoist: hoist, position: position); - public async Task EditRole(string serverId, string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null) + public Task EditRole(string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null) + => EditRole(_roles[roleId], name: name, permissions: permissions, color: color, hoist: hoist, position: position); + public async Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null) { - CheckReady(); - if (serverId == null) throw new NullReferenceException(nameof(serverId)); - if (roleId == null) throw new NullReferenceException(nameof(roleId)); + CheckReady(); + if (role == null) throw new ArgumentNullException(nameof(role)); - var response = await _api.EditRole(serverId, roleId, name: name, - permissions: permissions?.RawValue, color: color?.RawValue, hoist: hoist); - - var role = _roles[response.Id]; - if (role != null) - role.Update(response); + //TODO: check this null workaround later, should be fixed on Discord's end soon + var response = await _api.EditRole(role.ServerId, role.Id, + name: name ?? role.Name, + permissions: permissions?.RawValue ?? role.Permissions.RawValue, + color: color?.RawValue, + hoist: hoist); if (position != null) { @@ -136,8 +135,8 @@ namespace Discord public Task DeleteRole(string serverId, string roleId) { CheckReady(); - if (serverId == null) throw new NullReferenceException(nameof(serverId)); - if (roleId == null) throw new NullReferenceException(nameof(roleId)); + if (serverId == null) throw new ArgumentNullException(nameof(serverId)); + if (roleId == null) throw new ArgumentNullException(nameof(roleId)); return _api.DeleteRole(serverId, roleId); }