From 11b68981f99071dd7e1b831f890d72df4d745186 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:22:04 +0100 Subject: [PATCH] feat(handlers): add getGuildPreview() (#408) * add(handlers): getGuildPreview * update comment * check if guild is discoverable * remove checking since getGuild does not work on unjoined guilds --- src/api/handlers/guild.ts | 5 +++++ src/types/errors.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/src/api/handlers/guild.ts b/src/api/handlers/guild.ts index d7dd8343e..da75af44d 100644 --- a/src/api/handlers/guild.ts +++ b/src/api/handlers/guild.ts @@ -689,6 +689,11 @@ export async function unban(guildID: string, id: string) { return RequestManager.delete(endpoints.GUILD_BAN(guildID, id)); } +/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */ +export function getGuildPreview(guildID: string) { + return RequestManager.get(endpoints.GUILD_PREVIEW(guildID)); +} + /** Modify a guilds settings. Requires the MANAGE_GUILD permission. */ export async function editGuild(guildID: string, options: GuildEditOptions) { const hasPerm = await botHasPermission(guildID, ["MANAGE_GUILD"]); diff --git a/src/types/errors.ts b/src/types/errors.ts index 02fe6c29a..f99456106 100644 --- a/src/types/errors.ts +++ b/src/types/errors.ts @@ -42,4 +42,5 @@ export enum Errors { RULES_CHANNEL_CANNOT_BE_DELETED = "RULES_CHANNEL_CANNOT_BE_DELETED", UPDATES_CHANNEL_CANNOT_BE_DELETED = "UPDATES_CHANNEL_CANNOT_BE_DELETED", GUILD_NOT_FOUND = "GUILD_NOT_FOUND", + GUILD_NOT_DISCOVERABLE = "GUILD_NOT_DISCOVERABLE", }