From f9fddf7621a619860ddc681aa41604b535878561 Mon Sep 17 00:00:00 2001 From: ayntee Date: Fri, 13 Nov 2020 22:53:54 +0400 Subject: [PATCH] =?UTF-8?q?Server=20Templates=20=F0=9F=8E=89=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handlers/guild.ts | 28 ++++++++++++++++++++++++++++ src/types/guild.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/handlers/guild.ts b/src/handlers/guild.ts index 47385b112..8db3f76ea 100644 --- a/src/handlers/guild.ts +++ b/src/handlers/guild.ts @@ -622,3 +622,31 @@ export function getGuild(guildID: string, counts = true) { { with_counts: counts }, ) as Promise; } + +/** + * Get a template by its code + * @param code The code of the template + */ +export function getTemplate(code: string) { + const endpoint = `${endpoints.GUILDS}/templates/${code}`; + return RequestManager.get(endpoint); +} + +/** + * Create a new guild based on a template. + * NOTE: This endpoint can be used only by bots in less than 10 guilds. + * @param code the code of the template to create a new guild from + * @param name name of the guild (2-100 characters) + * @param icon base64 128x128 image for the guild icon + */ +export function createGuildFromTemplate( + code: string, + name: string, + icon?: any, +) { + const endpoint = `${endpoints.GUILDS}/templates/${code}`; + return RequestManager.post(endpoint, { + name, + icon, + }); +} diff --git a/src/types/guild.ts b/src/types/guild.ts index 7bcd4991e..e1a903fe7 100644 --- a/src/types/guild.ts +++ b/src/types/guild.ts @@ -1,3 +1,4 @@ +import { Guild } from "../structures/guild.ts"; import { ChannelCreatePayload, ChannelTypes } from "./channel.ts"; import { Emoji, StatusType } from "./discord.ts"; import { MemberCreatePayload } from "./member.ts"; @@ -606,3 +607,29 @@ export interface CreateServerOptions { /** the id of the channel where guild notices such as welcome messages and boost events are posted */ system_channel_id?: string; } + +// https://discord.com/developers/docs/resources/template#template-object +export interface GuildTemplate { + /** the template code (unique ID) */ + code: string; + /** template name */ + name: string; + /** the description for the template */ + description: string | null; + /** number of times this template has been used */ + usage_count: number; + /** the ID of the user who created the template */ + creator_id: string; + /** the user who created the template */ + user: UserPayload; + /** when this template was created */ + created_at: string; + /** when this template was last synced to the source guild */ + updated_at: string; + /** the ID of the guild this template is based on */ + source_guild_id: string; + /** the guild snapshot this template contains */ + serialized_source_guild: Guild; + /** whether the template has unsynced changes */ + is_dirty: boolean | null; +}