swc/bundler/tests/.cache/deno/4f8069e2135895a98ef3713b2006317ace3f8377.ts
강동윤 d60c3242af
fix(swc): Fix bugs (#1739)
swc_bundler:
 - Fix cycle detection for complex circular imports. (denoland/deno#10752)

swc_ecma_transforms_typescript:
 - Allow using large values for an enum variant.
2021-05-25 14:30:17 +09:00

36 lines
1.2 KiB
TypeScript

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/helpers/roles/create_role.ts
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { CreateGuildRole } from "../../types/guilds/create_guild_role.ts";
import type { Role } from "../../types/permissions/role.ts";
import { endpoints } from "../../util/constants.ts";
import { calculateBits, requireBotGuildPermissions } from "../../util/permissions.ts";
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
export async function createRole(guildId: bigint, options: CreateGuildRole, reason?: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod<Role>("post", endpoints.GUILD_ROLES(guildId), {
...options,
permissions: calculateBits(options?.permissions || []),
reason,
});
const role = await structures.createDiscordenoRole({
role: result,
guildId,
});
const guild = await cacheHandlers.get("guilds", guildId);
if (guild) {
guild.roles.set(role.id, role);
await cacheHandlers.set("guilds", guildId, guild);
}
return role;
}