fix: Check error 404 and return null for GetBanAsync (#1614)
This commit is contained in:
@@ -874,9 +874,13 @@ namespace Discord.API
|
|||||||
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
||||||
options = RequestOptions.CreateOrClone(options);
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
var ids = new BucketIds(guildId: guildId);
|
var ids = new BucketIds(guildId: guildId);
|
||||||
return await SendAsync<Ban>("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false);
|
return await SendAsync<Ban>("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; }
|
||||||
|
}
|
||||||
/// <exception cref="ArgumentException">
|
/// <exception cref="ArgumentException">
|
||||||
/// <paramref name="guildId"/> and <paramref name="userId"/> must not be equal to zero.
|
/// <paramref name="guildId"/> and <paramref name="userId"/> must not be equal to zero.
|
||||||
/// -and-
|
/// -and-
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace Discord.Rest
|
|||||||
public static async Task<RestBan> GetBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options)
|
public static async Task<RestBan> GetBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options)
|
||||||
{
|
{
|
||||||
var model = await client.ApiClient.GetGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false);
|
var model = await client.ApiClient.GetGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false);
|
||||||
return RestBan.Create(client, model);
|
return model == null ? null : RestBan.Create(client, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
|
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
|
||||||
|
|||||||
Reference in New Issue
Block a user