diff --git a/src/Discord.Net.Net45/Discord.Net.csproj b/src/Discord.Net.Net45/Discord.Net.csproj
index 34fb669bd..b00284b7d 100644
--- a/src/Discord.Net.Net45/Discord.Net.csproj
+++ b/src/Discord.Net.Net45/Discord.Net.csproj
@@ -166,9 +166,6 @@
DiscordAPIClientConfig.cs
-
- DiscordClient.Bans.cs
-
DiscordClient.Channels.cs
diff --git a/src/Discord.Net/DiscordClient.Bans.cs b/src/Discord.Net/DiscordClient.Bans.cs
deleted file mode 100644
index b66b76862..000000000
--- a/src/Discord.Net/DiscordClient.Bans.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System;
-using System.Net;
-using System.Threading.Tasks;
-
-namespace Discord
-{
- public class BanEventArgs : EventArgs
- {
- public long UserId { get; }
- public Server Server { get; }
-
- public BanEventArgs(long userId, Server server)
- {
- UserId = userId;
- Server = server;
- }
- }
-
- public partial class DiscordClient
- {
- public event EventHandler UserBanned;
- private void RaiseUserBanned(long userId, Server server)
- {
- if (UserBanned != null)
- RaiseEvent(nameof(UserBanned), () => UserBanned(this, new BanEventArgs(userId, server)));
- }
- public event EventHandler UserUnbanned;
- private void RaiseUserUnbanned(long userId, Server server)
- {
- if (UserUnbanned != null)
- RaiseEvent(nameof(UserUnbanned), () => UserUnbanned(this, new BanEventArgs(userId, server)));
- }
-
- /// Bans a user from the provided server.
- public Task Ban(User user)
- {
- if (user == null) throw new ArgumentNullException(nameof(user));
- if (user.Server == null) throw new ArgumentException("Unable to ban a user in a private chat.");
- CheckReady();
-
- return _api.BanUser(user.Server.Id, user.Id);
- }
-
- /// Unbans a user from the provided server.
- public async Task Unban(Server server, long userId)
- {
- if (server == null) throw new ArgumentNullException(nameof(server));
- if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
- CheckReady();
-
- try { await _api.UnbanUser(server.Id, userId).ConfigureAwait(false); }
- catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Discord.Net/DiscordClient.Users.cs b/src/Discord.Net/DiscordClient.Users.cs
index c8717aca3..47df1935d 100644
--- a/src/Discord.Net/DiscordClient.Users.cs
+++ b/src/Discord.Net/DiscordClient.Users.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Threading.Tasks;
namespace Discord
@@ -53,6 +54,17 @@ namespace Discord
IsSpeaking = isSpeaking;
}
}
+ public class BanEventArgs : EventArgs
+ {
+ public long UserId { get; }
+ public Server Server { get; }
+
+ public BanEventArgs(long userId, Server server)
+ {
+ UserId = userId;
+ Server = server;
+ }
+ }
public partial class DiscordClient
{
@@ -104,6 +116,18 @@ namespace Discord
if (ProfileUpdated != null)
RaiseEvent(nameof(ProfileUpdated), () => ProfileUpdated(this, EventArgs.Empty));
}
+ public event EventHandler UserBanned;
+ private void RaiseUserBanned(long userId, Server server)
+ {
+ if (UserBanned != null)
+ RaiseEvent(nameof(UserBanned), () => UserBanned(this, new BanEventArgs(userId, server)));
+ }
+ public event EventHandler UserUnbanned;
+ private void RaiseUserUnbanned(long userId, Server server)
+ {
+ if (UserUnbanned != null)
+ RaiseEvent(nameof(UserUnbanned), () => UserUnbanned(this, new BanEventArgs(userId, server)));
+ }
/// Returns the current logged-in user in a private channel.
internal User PrivateUser => _privateUser;
@@ -202,6 +226,7 @@ namespace Discord
{
if (user == null) throw new ArgumentNullException(nameof(user));
if (user.IsPrivate) throw new InvalidOperationException("Unable to kick users from a private channel");
+ CheckReady();
return _api.KickUser(user.Server.Id, user.Id);
}
@@ -209,15 +234,18 @@ namespace Discord
{
if (user == null) throw new ArgumentNullException(nameof(user));
if (user.IsPrivate) throw new InvalidOperationException("Unable to ban users from a private channel");
+ CheckReady();
return _api.BanUser(user.Server.Id, user.Id);
}
- public Task UnbanUser(Server server, long userId)
+ public async Task UnbanUser(Server server, long userId)
{
if (server == null) throw new ArgumentNullException(nameof(server));
if (userId <= 0) throw new ArgumentOutOfRangeException(nameof(userId));
+ CheckReady();
- return _api.UnbanUser(server.Id, userId);
+ try { await _api.UnbanUser(server.Id, userId).ConfigureAwait(false); }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}
public async Task PruneUsers(Server server, int days, bool simulate = false)