From 660d4b0bf62152a8b0b1ee2e2bac74bfed9ef6b5 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 15 Apr 2017 18:03:19 -0400 Subject: [PATCH] Add an upper limit to prune length when banning a user (#611) Messages may only be pruned between 0 and 7 days, otherwise a 400 will be thrown. --- src/Discord.Net.Core/Entities/Guilds/IGuild.cs | 2 ++ src/Discord.Net.Rest/DiscordRestApiClient.cs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index 6c7b73370..8da731855 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -65,8 +65,10 @@ namespace Discord /// Gets a collection of all users banned on this guild. Task> GetBansAsync(RequestOptions options = null); /// Bans the provided user from this guild and optionally prunes their recent messages. + /// The number of days to remove messages from this user for - must be between [0, 7] Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null); /// Bans the provided user id from this guild and optionally prunes their recent messages. + /// The number of days to remove messages from this user for - must be between [0, 7] Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null); /// Unbans the provided user if it is currently banned. Task RemoveBanAsync(IUser user, RequestOptions options = null); diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index c57d15645..a632e5d42 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -798,7 +798,8 @@ namespace Discord.API Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(userId, 0, nameof(userId)); Preconditions.NotNull(args, nameof(args)); - Preconditions.AtLeast(args.DeleteMessageDays, 0, nameof(args.DeleteMessageDays)); + Preconditions.AtLeast(args.DeleteMessageDays, 0, nameof(args.DeleteMessageDays), "Prune length must be within [0, 7]"); + Preconditions.AtMost(args.DeleteMessageDays, 7, nameof(args.DeleteMessageDays), "Prune length must be within [0, 7]"); options = RequestOptions.CreateOrClone(options); var ids = new BucketIds(guildId: guildId);