mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 09:20:08 +00:00
26 lines
837 B
TypeScript
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)),
|
|
});
|
|
}
|