mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
add: delete thread functionality
This commit is contained in:
@@ -1,27 +1,40 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { rest } from "../../rest/rest.ts";
|
import { rest } from "../../rest/rest.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
|
import { ChannelTypes } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||||
export async function deleteChannel(
|
export async function deleteChannel(
|
||||||
guildId: string,
|
|
||||||
channelId: string,
|
channelId: string,
|
||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<undefined> {
|
) {
|
||||||
await requireBotGuildPermissions(guildId, ["MANAGE_CHANNELS"]);
|
const channel = await cacheHandlers.get("channels", channelId);
|
||||||
|
|
||||||
const guild = await cacheHandlers.get("guilds", guildId);
|
if (channel?.guildId) {
|
||||||
|
const guild = await cacheHandlers.get("guilds", channel.guildId);
|
||||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
|
||||||
if (guild?.rulesChannelId === channelId) {
|
// 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);
|
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guild?.publicUpdatesChannelId === channelId) {
|
if (guild.publicUpdatesChannelId === channelId) {
|
||||||
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
|
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return await rest.runMethod<undefined>(
|
return await rest.runMethod<undefined>(
|
||||||
"delete",
|
"delete",
|
||||||
|
|||||||
Reference in New Issue
Block a user