| @@ -219,7 +219,7 @@ namespace Discord.API | |||||
| switch (channels.Length) | switch (channels.Length) | ||||
| { | { | ||||
| case 0: | case 0: | ||||
| throw new ArgumentOutOfRangeException(nameof(args)); | |||||
| return; | |||||
| case 1: | case 1: | ||||
| await ModifyGuildChannel(channels[0].Id, new ModifyGuildChannelParams { Position = channels[0].Position }).ConfigureAwait(false); | await ModifyGuildChannel(channels[0].Id, new ModifyGuildChannelParams { Position = channels[0].Position }).ConfigureAwait(false); | ||||
| break; | break; | ||||
| @@ -476,8 +476,10 @@ namespace Discord.API | |||||
| if (result.Count > 1) | if (result.Count > 1) | ||||
| return result.SelectMany(x => x); | return result.SelectMany(x => x); | ||||
| else | |||||
| else if (result.Count == 1) | |||||
| return result[0]; | return result[0]; | ||||
| else | |||||
| return Array.Empty<GuildMember>(); | |||||
| } | } | ||||
| public async Task RemoveGuildMember(ulong guildId, ulong userId) | public async Task RemoveGuildMember(ulong guildId, ulong userId) | ||||
| { | { | ||||
| @@ -535,7 +537,7 @@ namespace Discord.API | |||||
| switch (roles.Length) | switch (roles.Length) | ||||
| { | { | ||||
| case 0: | case 0: | ||||
| throw new ArgumentOutOfRangeException(nameof(args)); | |||||
| return Array.Empty<Role>(); | |||||
| case 1: | case 1: | ||||
| return ImmutableArray.Create(await ModifyGuildRole(guildId, roles[0].Id, roles[0]).ConfigureAwait(false)); | return ImmutableArray.Create(await ModifyGuildRole(guildId, roles[0].Id, roles[0]).ConfigureAwait(false)); | ||||
| default: | default: | ||||
| @@ -580,10 +582,12 @@ namespace Discord.API | |||||
| if (models.Length != DiscordConfig.MaxMessagesPerBatch) { i++; break; } | if (models.Length != DiscordConfig.MaxMessagesPerBatch) { i++; break; } | ||||
| } | } | ||||
| if (runs > 1) | |||||
| return result.Take(runs).SelectMany(x => x); | |||||
| else | |||||
| if (i > 1) | |||||
| return result.Take(i).SelectMany(x => x); | |||||
| else if (i == 1) | |||||
| return result[0]; | return result[0]; | ||||
| else | |||||
| return Array.Empty<Message>(); | |||||
| } | } | ||||
| public Task<Message> CreateMessage(ulong channelId, CreateMessageParams args) | public Task<Message> CreateMessage(ulong channelId, CreateMessageParams args) | ||||
| => CreateMessage(0, channelId, args); | => CreateMessage(0, channelId, args); | ||||
| @@ -636,7 +640,7 @@ namespace Discord.API | |||||
| switch (messageIds.Length) | switch (messageIds.Length) | ||||
| { | { | ||||
| case 0: | case 0: | ||||
| throw new ArgumentOutOfRangeException(nameof(args.MessageIds)); | |||||
| return; | |||||
| case 1: | case 1: | ||||
| await DeleteMessage(guildId, channelId, messageIds[0]).ConfigureAwait(false); | await DeleteMessage(guildId, channelId, messageIds[0]).ConfigureAwait(false); | ||||
| break; | break; | ||||
| @@ -81,11 +81,11 @@ namespace Discord.Rest | |||||
| { | { | ||||
| var emojis = ImmutableArray.CreateBuilder<Emoji>(model.Emojis.Length); | var emojis = ImmutableArray.CreateBuilder<Emoji>(model.Emojis.Length); | ||||
| for (int i = 0; i < model.Emojis.Length; i++) | for (int i = 0; i < model.Emojis.Length; i++) | ||||
| emojis[i] = new Emoji(model.Emojis[i]); | |||||
| emojis.Add(new Emoji(model.Emojis[i])); | |||||
| Emojis = emojis.ToArray(); | Emojis = emojis.ToArray(); | ||||
| } | } | ||||
| else | else | ||||
| Emojis = ImmutableArray<Emoji>.Empty; | |||||
| Emojis = Array.Empty<Emoji>(); | |||||
| var roles = new ConcurrentDictionary<ulong, Role>(1, model.Roles?.Length ?? 0); | var roles = new ConcurrentDictionary<ulong, Role>(1, model.Roles?.Length ?? 0); | ||||
| if (model.Roles != null) | if (model.Roles != null) | ||||
| @@ -68,7 +68,7 @@ namespace Discord.Rest | |||||
| Attachments = ImmutableArray.Create(attachments); | Attachments = ImmutableArray.Create(attachments); | ||||
| } | } | ||||
| else | else | ||||
| Attachments = ImmutableArray<Attachment>.Empty; | |||||
| Attachments = Array.Empty<Attachment>(); | |||||
| if (model.Embeds.Length > 0) | if (model.Embeds.Length > 0) | ||||
| { | { | ||||
| @@ -78,18 +78,18 @@ namespace Discord.Rest | |||||
| Embeds = ImmutableArray.Create(embeds); | Embeds = ImmutableArray.Create(embeds); | ||||
| } | } | ||||
| else | else | ||||
| Embeds = ImmutableArray<Embed>.Empty; | |||||
| Embeds = Array.Empty<Embed>(); | |||||
| if (model.Mentions.Length > 0) | if (model.Mentions.Length > 0) | ||||
| { | { | ||||
| var discord = Discord; | var discord = Discord; | ||||
| var builder = ImmutableArray.CreateBuilder<PublicUser>(model.Mentions.Length); | var builder = ImmutableArray.CreateBuilder<PublicUser>(model.Mentions.Length); | ||||
| for (int i = 0; i < model.Mentions.Length; i++) | for (int i = 0; i < model.Mentions.Length; i++) | ||||
| builder[i] = new PublicUser(discord, model.Mentions[i]); | |||||
| builder.Add(new PublicUser(discord, model.Mentions[i])); | |||||
| MentionedUsers = builder.ToArray(); | MentionedUsers = builder.ToArray(); | ||||
| } | } | ||||
| else | else | ||||
| MentionedUsers = ImmutableArray<PublicUser>.Empty; | |||||
| MentionedUsers = Array.Empty<PublicUser>(); | |||||
| MentionedChannelIds = MentionHelper.GetChannelMentions(model.Content); | MentionedChannelIds = MentionHelper.GetChannelMentions(model.Content); | ||||
| MentionedRoleIds = MentionHelper.GetRoleMentions(model.Content); | MentionedRoleIds = MentionHelper.GetRoleMentions(model.Content); | ||||
| if (model.IsMentioningEveryone) | if (model.IsMentioningEveryone) | ||||
| @@ -39,9 +39,9 @@ namespace Discord.Rest | |||||
| Nickname = model.Nick; | Nickname = model.Nick; | ||||
| var roles = ImmutableArray.CreateBuilder<Role>(model.Roles.Length + 1); | var roles = ImmutableArray.CreateBuilder<Role>(model.Roles.Length + 1); | ||||
| roles[0] = Guild.EveryoneRole; | |||||
| roles.Add(Guild.EveryoneRole); | |||||
| for (int i = 0; i < model.Roles.Length; i++) | for (int i = 0; i < model.Roles.Length; i++) | ||||
| roles[i + 1] = Guild.GetRole(model.Roles[i]); | |||||
| roles.Add(Guild.GetRole(model.Roles[i])); | |||||
| _roles = roles.ToImmutable(); | _roles = roles.ToImmutable(); | ||||
| } | } | ||||