Files
discordeno/helpers/templates/createGuildTemplate.ts
Skillz4Killz a0a1554756 refactor: typings using ReturnType (#2105)
* fix: check new types idea

* fix: type errors

* fix: new style

* fix: more cleanup

* fix: more cleanup

* fix: cleanup audit logs

* fix: cleanup stickers

* fix: cleanup integrations

* fix: more cleanup

* fix: organize into 1 place

* fix: few errors

* fix: some broken import fixes

* fix: quite a lot of fixes across the board

* fix: more fixes for broken imports

* fix: more fixes for broken imports

* fix: handler imports

* fix: all remaining import errors

* fix: more errors needing fixes

* fix: clearing up transformers

* fix: few moer types

* fix: more cleanup of extra types

* fix: fmt

* fix: cleanup discordeno file

* Nuke Base Types (#2102)

* fix: cleanup snake stuff

* convert camelCase to snake_case (#2103)

* fix: add camelize

* fix: finalize remaining errors

* fix: imports in test

Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
2022-03-14 22:11:22 -04:00

55 lines
1.9 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { Guild } from "../../transformers/guild.ts";
import { User } from "../../transformers/member.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: Template) {
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), {
code: data.code,
name: data.name,
description: data.description,
usage_count: data.usageCount,
creator_id: data.creatorId,
creator: data.creator,
created_at: data.createdAt,
updated_at: data.updatedAt,
source_guild_id: data.sourceGuildId,
serialized_source_guild: data.serializedSourceGuild,
is_dirty: data.isDirty,
});
}
export interface Template {
/** The template code (unique Id) */
code: string;
/** Template name */
name: string;
/** The description for the template */
description: string;
/** Number of times this template has been used */
usageCount: number;
/** The Id of the user who created the template */
creatorId: string;
/** The user who created the template */
creator: User;
/** When this template was created */
createdAt: string;
/** When this template was last synced to the source guild */
updatedAt: string;
/** The Id of the guild this template is based on */
sourceGuildId: string;
/** The guild snapshot this template contains */
serializedSourceGuild: Partial<Guild>;
/** Whether the template has unsynced changes */
isDirty: boolean;
}