swc/bundler/tests/.cache/deno/79f8922dd9d9b5284e4c47291588712d1e3232c7.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

39 lines
1.5 KiB
TypeScript

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/helpers/channels/delete_channel.ts
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/discordeno/errors.ts";
import { ChannelTypes } from "../../types/channels/channel_types.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function deleteChannel(channelId: bigint, reason?: string) {
const channel = await cacheHandlers.get("channels", channelId);
if (channel?.guildId) {
const guild = await cacheHandlers.get("guilds", channel.guildId);
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
// TODO(threads): check if this requires guild perms or channel is enough
await requireBotGuildPermissions(
guild,
[ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
channel.type
)
? ["MANAGE_THREADS"]
: ["MANAGE_CHANNELS"]
);
if (guild.rulesChannelId === channelId) {
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
}
if (guild.publicUpdatesChannelId === channelId) {
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
}
}
return await rest.runMethod<undefined>("delete", endpoints.CHANNEL_BASE(channelId), { reason });
}