Files
discordeno/helpers/templates/editGuildTemplate.ts
2022-02-11 09:49:53 +00:00

28 lines
936 B
TypeScript

import type { ModifyGuildTemplate } from "../../types/templates/modifyGuildTemplate.ts";
import type { Template } from "../../types/templates/template.ts";
import type { Bot } from "../../bot.ts";
/**
* Edit a template's metadata.
* Requires the `MANAGE_GUILD` permission.
*/
export async function editGuildTemplate(bot: Bot, guildId: bigint, templateCode: string, data: ModifyGuildTemplate) {
if (data.name?.length && (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<Template>(
bot.rest,
"patch",
`${bot.constants.endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
{
name: data.name,
description: data.description,
},
);
}