templates

This commit is contained in:
ITOH
2021-04-24 19:42:11 +02:00
parent 5793351fef
commit 973ec219cc
7 changed files with 18 additions and 34 deletions
+4 -5
View File
@@ -1,9 +1,8 @@
import { rest } from "../../rest/rest.ts";
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
import { Template } from "../../types/templates/template.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/**
* Returns an array of templates.
@@ -12,15 +11,15 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
export async function getGuildTemplates(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const templates = (await rest.runMethod(
const templates = await rest.runMethod<Template[]>(
"get",
endpoints.GUILD_TEMPLATES(guildId),
)) as DiscordTemplate[];
);
return new Collection(
templates.map((template) => [
template.code,
snakeKeysToCamelCase<Template>(template),
template,
]),
);
}