Browse Source

Added Server.GetBans

tags/docs-0.9
RogueException 9 years ago
parent
commit
51fd771af9
3 changed files with 34 additions and 0 deletions
  1. +3
    -0
      src/Discord.Net.Net45/Discord.Net.csproj
  2. +20
    -0
      src/Discord.Net/API/Client/Rest/GetBans.cs
  3. +11
    -0
      src/Discord.Net/Models/Server.cs

+ 3
- 0
src/Discord.Net.Net45/Discord.Net.csproj View File

@@ -278,6 +278,9 @@
<Compile Include="..\Discord.Net\API\Client\Rest\Gateway.cs">
<Link>API\Client\Rest\Gateway.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\GetBans.cs">
<Link>API\Client\Rest\GetBans.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Rest\GetInvite.cs">
<Link>API\Client\Rest\GetInvite.cs</Link>
</Compile>


+ 20
- 0
src/Discord.Net/API/Client/Rest/GetBans.cs View File

@@ -0,0 +1,20 @@
using Newtonsoft.Json;

namespace Discord.API.Client.Rest
{
[JsonObject(MemberSerialization.OptIn)]
public sealed class GetBansRequest : IRestRequest<UserReference[]>
{
string IRestRequest.Method => "GET";
string IRestRequest.Endpoint => $"guilds/{GuildId}/bans";
object IRestRequest.Payload => null;
bool IRestRequest.IsPrivate => false;

public ulong GuildId { get; }

public GetBansRequest(ulong guildId)
{
GuildId = guildId;
}
}
}

+ 11
- 0
src/Discord.Net/Models/Server.cs View File

@@ -172,6 +172,17 @@ namespace Discord
}

#region Bans
public async Task<IEnumerable<User>> GetBans()
{
var response = await Client.ClientAPI.Send(new GetBansRequest(Id)).ConfigureAwait(false);
return response.Select(x =>
{
var user = new User(Client, x.Id, this);
user.Update(x);
return user;
});
}

public Task Ban(User user, int pruneDays = 0)
{
var request = new AddGuildBanRequest(user.Server.Id, user.Id)


Loading…
Cancel
Save