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

26 lines
837 B
TypeScript

import type { Guild } from "../../types/guilds/guild.ts";
import type { CreateGuildFromTemplate } from "../../types/templates/createGuildFromTemplate.ts";
import type { Bot } from "../../bot.ts";
/**
* Create a new guild based on a template
* NOTE: This endpoint can be used only by bots in less than 10 guilds.
*/
export async function createGuildFromTemplate(bot: Bot, templateCode: string, data: CreateGuildFromTemplate) {
if (data.icon) {
data.icon = await bot.utils.urlToBase64(data.icon);
}
const createdGuild = await bot.rest.runMethod<Guild>(
bot.rest,
"post",
bot.constants.endpoints.GUILD_TEMPLATE(templateCode),
data,
);
return bot.transformers.guild(bot, {
guild: createdGuild,
shardId: bot.utils.calculateShardId(bot.gateway, bot.transformers.snowflake(createdGuild.id)),
});
}