Browse Source

Initial fix (#1160)

tags/2.0
Still Hsu Christopher F 6 years ago
parent
commit
c9ba79ec80
3 changed files with 16 additions and 4 deletions
  1. +10
    -0
      src/Discord.Net.Rest/API/Common/InviteVanity.cs
  2. +2
    -2
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  3. +4
    -2
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs

+ 10
- 0
src/Discord.Net.Rest/API/Common/InviteVanity.cs View File

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

namespace Discord.API
{
public class InviteVanity
{
[JsonProperty("code")]
public string Code { get; set; }
}
}

+ 2
- 2
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -929,13 +929,13 @@ namespace Discord.API
} }
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; }
} }
public async Task<InviteMetadata> GetVanityInviteAsync(ulong guildId, RequestOptions options = null)
public async Task<InviteVanity> GetVanityInviteAsync(ulong guildId, RequestOptions options = null)
{ {
Preconditions.NotEqual(guildId, 0, nameof(guildId)); Preconditions.NotEqual(guildId, 0, nameof(guildId));
options = RequestOptions.CreateOrClone(options); options = RequestOptions.CreateOrClone(options);


var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
return await SendAsync<InviteMetadata>("GET", () => $"guilds/{guildId}/vanity-url", ids, options: options).ConfigureAwait(false);
return await SendAsync<InviteVanity>("GET", () => $"guilds/{guildId}/vanity-url", ids, options: options).ConfigureAwait(false);
} }
public async Task<IReadOnlyCollection<InviteMetadata>> GetGuildInvitesAsync(ulong guildId, RequestOptions options = null) public async Task<IReadOnlyCollection<InviteMetadata>> GetGuildInvitesAsync(ulong guildId, RequestOptions options = null)
{ {


+ 4
- 2
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -213,8 +213,10 @@ namespace Discord.Rest
public static async Task<RestInviteMetadata> GetVanityInviteAsync(IGuild guild, BaseDiscordClient client, public static async Task<RestInviteMetadata> GetVanityInviteAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options) RequestOptions options)
{ {
var model = await client.ApiClient.GetVanityInviteAsync(guild.Id, options).ConfigureAwait(false);
return RestInviteMetadata.Create(client, guild, null, model);
var vanityModel = await client.ApiClient.GetVanityInviteAsync(guild.Id, options).ConfigureAwait(false);
if (vanityModel == null) throw new InvalidOperationException("This guild does not have a vanity URL.");
var inviteModel = await client.ApiClient.GetInviteAsync(vanityModel.Code, options).ConfigureAwait(false);
return RestInviteMetadata.Create(client, guild, null, inviteModel);
} }


//Roles //Roles


Loading…
Cancel
Save