Added DeleteGuildRequest
This commit is contained in:
@@ -256,6 +256,9 @@
|
||||
<Compile Include="..\Discord.Net\API\Client\Rest\DeleteChannel.cs">
|
||||
<Link>API\Client\Rest\DeleteChannel.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net\API\Client\Rest\DeleteGuild.cs">
|
||||
<Link>API\Client\Rest\DeleteGuild.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net\API\Client\Rest\DeleteInvite.cs">
|
||||
<Link>API\Client\Rest\DeleteInvite.cs</Link>
|
||||
</Compile>
|
||||
|
||||
20
src/Discord.Net/API/Client/Rest/DeleteGuild.cs
Normal file
20
src/Discord.Net/API/Client/Rest/DeleteGuild.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Client.Rest
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class DeleteGuildRequest : IRestRequest<Guild>
|
||||
{
|
||||
string IRestRequest.Method => "DELETE";
|
||||
string IRestRequest.Endpoint => $"guilds/{GuildId}";
|
||||
object IRestRequest.Payload => null;
|
||||
bool IRestRequest.IsPrivate => false;
|
||||
|
||||
public ulong GuildId { get; set; }
|
||||
|
||||
public DeleteGuildRequest(ulong guildId)
|
||||
{
|
||||
GuildId = guildId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,17 +208,13 @@ namespace Discord
|
||||
/// <summary> Leaves this server. This function will fail if you're the owner - use Delete instead. </summary>
|
||||
public async Task Leave()
|
||||
{
|
||||
if (_ownerId == CurrentUser.Id)
|
||||
throw new InvalidOperationException("Unable to leave a server you own, use Server.Delete instead");
|
||||
try { await Client.ClientAPI.Send(new LeaveGuildRequest(Id)).ConfigureAwait(false); }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
/// <summary> Deletes this server. This function will fail if you're not the owner - use Leave instead. </summary>
|
||||
public async Task Delete()
|
||||
{
|
||||
if (_ownerId != CurrentUser.Id)
|
||||
throw new InvalidOperationException("Unable to delete a server you don't own, use Server.Leave instead");
|
||||
try { await Client.ClientAPI.Send(new LeaveGuildRequest(Id)).ConfigureAwait(false); }
|
||||
try { await Client.ClientAPI.Send(new DeleteGuildRequest(Id)).ConfigureAwait(false); }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user