diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts
index 8ec801c0..20a35b95 100644
--- a/src/util/entities/Channel.ts
+++ b/src/util/entities/Channel.ts
@@ -20,7 +20,17 @@ import { HTTPError } from "lambert-server";
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
import { DmChannelDTO } from "../dtos";
import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces";
-import { InvisibleCharacters, Snowflake, emitEvent, getPermission, trimSpecial, Permissions, BitField } from "../util";
+import {
+ InvisibleCharacters,
+ Snowflake,
+ containsAll,
+ emitEvent,
+ getPermission,
+ trimSpecial,
+ DiscordApiErrors,
+ Permissions,
+ BitField
+} from "../util";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { Invite } from "./Invite";
@@ -263,7 +273,7 @@ export class Channel extends BaseClass {
if (otherRecipientsUsers.length !== recipients.length) {
throw new HTTPError("Recipient/s not found");
}
- **/
+ **/
const type = recipients.length > 1 ? ChannelType.GROUP_DM : ChannelType.DM;
@@ -377,7 +387,6 @@ export class Channel extends BaseClass {
static async deleteChannel(channel: Channel) {
// TODO Delete attachments from the CDN for messages in the channel
- await Channel.delete({ id: channel.id });
if (channel.guild_id) {
const guild = await Guild.findOneOrFail({
@@ -385,9 +394,42 @@ export class Channel extends BaseClass {
select: { channel_ordering: true },
});
- const updatedOrdering = guild.channel_ordering.filter((id) => id != channel.id);
- await Guild.update({ id: channel.guild_id }, { channel_ordering: updatedOrdering });
- }
+ if (guild.features.includes("COMMUNITY")) {
+ if (
+ [
+ guild.afk_channel_id,
+ guild.system_channel_id,
+ guild.rules_channel_id,
+ guild.public_updates_channel_id,
+ ].includes(channel.id)
+ ) {
+ throw DiscordApiErrors.CANNOT_DELETE_COMMUNITY_REQUIRED_CHANNEL;
+ }
+ }
+ else {
+ if (guild.afk_channel_id === channel.id) {
+ guild.afk_channel_id = null;
+ }
+ if (guild.system_channel_id === channel.id) {
+ guild.system_channel_id = null;
+ }
+ if (guild.rules_channel_id === channel.id) {
+ guild.rules_channel_id = null;
+ }
+ if (guild.public_updates_channel_id === channel.id) {
+ guild.public_updates_channel_id = null;
+ }
+ }
+
+ await Channel.delete({ id: channel.id });
+
+ const updatedOrdering = guild.channel_ordering.filter(
+ (id) => id != channel.id,
+ );
+ await Guild.update(
+ { id: channel.guild_id },
+ { channel_ordering: updatedOrdering },
+ );
}
static async calculatePosition(channel_id: string, guild_id: string, guild?: Guild) {
|