| @@ -11,6 +11,8 @@ namespace Discord | |||||
| int AFKTimeout { get; } | int AFKTimeout { get; } | ||||
| /// <summary> Returns true if this guild is embeddable (e.g. widget) </summary> | /// <summary> Returns true if this guild is embeddable (e.g. widget) </summary> | ||||
| bool IsEmbeddable { get; } | bool IsEmbeddable { get; } | ||||
| /// <summary> Returns true if the current user owns this guild. </summary> | |||||
| bool IsOwner { get; } | |||||
| /// <summary> Gets the name of this guild. </summary> | /// <summary> Gets the name of this guild. </summary> | ||||
| string Name { get; } | string Name { get; } | ||||
| int VerificationLevel { get; } | int VerificationLevel { get; } | ||||
| @@ -46,6 +46,8 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id); | public DateTime CreatedAt => DateTimeHelper.FromSnowflake(Id); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public bool IsOwner => OwnerId == Discord.CurrentUser.Id; | |||||
| /// <inheritdoc /> | |||||
| public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId); | public string IconUrl => API.CDN.GetGuildIconUrl(Id, _iconId); | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public string SplashUrl => API.CDN.GetGuildSplashUrl(Id, _splashId); | public string SplashUrl => API.CDN.GetGuildSplashUrl(Id, _splashId); | ||||
| @@ -155,11 +157,15 @@ namespace Discord.Rest | |||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public async Task Leave() | public async Task Leave() | ||||
| { | { | ||||
| if (IsOwner) | |||||
| throw new InvalidOperationException("Unable to leave a guild the current user owns."); | |||||
| await Discord.BaseClient.LeaveGuild(Id).ConfigureAwait(false); | await Discord.BaseClient.LeaveGuild(Id).ConfigureAwait(false); | ||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public async Task Delete() | public async Task Delete() | ||||
| { | { | ||||
| if (!IsOwner) | |||||
| throw new InvalidOperationException("Unable to delete a guild the current user does not own."); | |||||
| await Discord.BaseClient.DeleteGuild(Id).ConfigureAwait(false); | await Discord.BaseClient.DeleteGuild(Id).ConfigureAwait(false); | ||||
| } | } | ||||
| @@ -41,14 +41,14 @@ namespace Discord.Rest | |||||
| public async Task Leave() | public async Task Leave() | ||||
| { | { | ||||
| if (IsOwner) | if (IsOwner) | ||||
| throw new InvalidOperationException("Unable to leave a guild the current user owns, use Delete() instead."); | |||||
| throw new InvalidOperationException("Unable to leave a guild the current user owns."); | |||||
| await Discord.BaseClient.LeaveGuild(Id).ConfigureAwait(false); | await Discord.BaseClient.LeaveGuild(Id).ConfigureAwait(false); | ||||
| } | } | ||||
| /// <inheritdoc /> | /// <inheritdoc /> | ||||
| public async Task Delete() | public async Task Delete() | ||||
| { | { | ||||
| if (!IsOwner) | if (!IsOwner) | ||||
| throw new InvalidOperationException("Unable to leave a guild the current user owns, use Delete() instead."); | |||||
| throw new InvalidOperationException("Unable to delete a guild the current user does not own."); | |||||
| await Discord.BaseClient.DeleteGuild(Id).ConfigureAwait(false); | await Discord.BaseClient.DeleteGuild(Id).ConfigureAwait(false); | ||||
| } | } | ||||