Files
discordeno/helpers/templates/createGuildTemplate.ts
ITOH 2c2ccb252c feat(helpers,types)!: add guild template transformer (#2132)
* feat(helpers,types)!: add guild template transformer
This adds a template transformer. Also this fixes incorrect type definitions regarding templates.

Breaking Change: The previously called `Template` interface which was used for creating templates has been renamed to `CreateTemplate`

* fmt

* forgot to add this

* use data
2022-03-25 06:15:17 -04:00

28 lines
870 B
TypeScript

import type { Bot } from "../../bot.ts";
import { DiscordTemplate } from "../../types/discord.ts";
/** Creates a template for the guild. Requires the `MANAGE_GUILD` permission. */
export async function createGuildTemplate(bot: Bot, guildId: bigint, data: CreateTemplate) {
if (data.name.length < 1 || data.name.length > 100) {
throw new Error("The name can only be in between 1-100 characters.");
}
if (data.description?.length && data.description.length > 120) {
throw new Error("The description can only be in between 0-120 characters.");
}
return await bot.rest.runMethod<DiscordTemplate>(
bot.rest,
"post",
bot.constants.endpoints.GUILD_TEMPLATES(guildId),
data,
);
}
export interface CreateTemplate {
/** Name which the template should have */
name: string;
/** Description of the template */
description?: string;
}