diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index 9a805b2bb..8510207d7 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -1,7 +1,6 @@ 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"; @@ -14,14 +13,7 @@ export async function deleteChannel(channelId: bigint, reason?: string) { 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"] - ); + await requireBotGuildPermissions(guild, channel.isThreadChannel ? ["MANAGE_THREADS"] : ["MANAGE_CHANNELS"]); if (guild.rulesChannelId === channelId) { throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED); } diff --git a/src/helpers/channels/edit_channel.ts b/src/helpers/channels/edit_channel.ts index 0d61d4574..5cd8befb4 100644 --- a/src/helpers/channels/edit_channel.ts +++ b/src/helpers/channels/edit_channel.ts @@ -4,7 +4,6 @@ import { rest } from "../../rest/rest.ts"; import type { DiscordenoChannel } from "../../structures/channel.ts"; import { structures } from "../../structures/mod.ts"; import type { Channel } from "../../types/channels/channel.ts"; -import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import type { ModifyChannel } from "../../types/channels/modify_channel.ts"; import type { ModifyThread } from "../../types/channels/threads/modify_thread.ts"; import type { PermissionStrings } from "../../types/permissions/permission_strings.ts"; @@ -19,13 +18,7 @@ export async function editChannel(channelId: bigint, options: ModifyChannel | Mo const channel = await cacheHandlers.get("channels", channelId); if (channel) { - if ( - [ - DiscordChannelTypes.GuildNewsThread, - DiscordChannelTypes.GuildPivateThread, - DiscordChannelTypes.GuildPublicThread, - ].includes(channel.type) - ) { + if (channel.isThreadChannel) { const permissions = new Set(); if (hasOwnProperty(options, "archive") && options.archive === false) { diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index 173a73f3b..5fd7a922e 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -20,7 +20,7 @@ export async function startTyping(channelId: bigint) { DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText, DiscordChannelTypes.GuildNewsThread, - DiscordChannelTypes.GuildPivateThread, + DiscordChannelTypes.GuildPrivateThread, DiscordChannelTypes.GuildPublicThread, ].includes(channel.type) ) { diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 590573b51..d45d4a7ad 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -24,7 +24,7 @@ export async function sendMessage(channelId: bigint, content: string | CreateMes DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText, DiscordChannelTypes.GuildPublicThread, - DiscordChannelTypes.GuildPivateThread, + DiscordChannelTypes.GuildPrivateThread, DiscordChannelTypes.GuildNewsThread, ].includes(channel.type) ) { diff --git a/src/structures/channel.ts b/src/structures/channel.ts index c7fb45fff..4797ee424 100644 --- a/src/structures/channel.ts +++ b/src/structures/channel.ts @@ -82,6 +82,13 @@ const baseChannel: Partial = { get isGuildTextBasedChannel() { return [DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText].includes(this.type!); }, + get isThreadChannel() { + return [ + DiscordChannelTypes.GuildNewsThread, + DiscordChannelTypes.GuildPrivateThread, + DiscordChannelTypes.GuildPublicThread, + ].includes(this.type!); + }, send(content) { return sendMessage(this.id!, content); }, @@ -195,6 +202,8 @@ export interface DiscordenoChannel isNewsChannel: boolean; /** Whether the channel is a news or text channel in a guild. */ isGuildTextBasedChannel: boolean; + /** Whether the channel is a thread type channel. */ + isThreadChannel: boolean; // METHODS