diff --git a/src/Discord.Net.Core/Utils/Preconditions.cs b/src/Discord.Net.Core/Utils/Preconditions.cs index 705a15249..42184be4e 100644 --- a/src/Discord.Net.Core/Utils/Preconditions.cs +++ b/src/Discord.Net.Core/Utils/Preconditions.cs @@ -192,5 +192,7 @@ namespace Discord throw new ArgumentOutOfRangeException(name, "Messages must be younger than two weeks old."); } } + + public static void LoggedInAs(TokenType token, TokenType existing) { if (token != existing) throw new NotSupportedException($"Must be logged in as a {token} to use this endpoint"); } } } diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index e690ac4f5..0f99bca0e 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -1077,12 +1077,17 @@ namespace Discord.API //Relationships public async Task> GetRelationshipsAsync(RequestOptions options = null) { + Preconditions.LoggedInAs(TokenType.User, AuthTokenType); + options = RequestOptions.CreateOrClone(options); + return await SendAsync>("GET", () => "users/@me/relationships", new BucketIds(), options: options).ConfigureAwait(false); } public async Task AddFriendAsync(ulong userId, RequestOptions options = null) { Preconditions.NotEqual(userId, 0, nameof(userId)); + Preconditions.LoggedInAs(TokenType.User, AuthTokenType); + options = RequestOptions.CreateOrClone(options); await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new object(), new BucketIds(), options: options).ConfigureAwait(false); @@ -1090,6 +1095,8 @@ namespace Discord.API public async Task BlockUserAsync(ulong userId, RequestOptions options = null) { Preconditions.NotEqual(userId, 0, nameof(userId)); + Preconditions.LoggedInAs(TokenType.User, AuthTokenType); + options = RequestOptions.CreateOrClone(options); await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new { type = 2 }, new BucketIds(), options: options).ConfigureAwait(false); @@ -1097,6 +1104,8 @@ namespace Discord.API public async Task RemoveRelationshipAsync(ulong userId, RequestOptions options = null) { Preconditions.NotEqual(userId, 0, nameof(userId)); + Preconditions.LoggedInAs(TokenType.User, AuthTokenType); + options = RequestOptions.CreateOrClone(options); await SendAsync("DELETE", () => $"users/@me/relationships/{userId}", new BucketIds(), options: options).ConfigureAwait(false);