feat(handlers): inhibitors for deleteChannel() (#401)

* better deleteChannel function

* throw error if guild wasn't found

* remove dm close ability

* change this comment again

* guildID should be first
This commit is contained in:
ITOH
2021-01-19 15:20:12 +01:00
committed by GitHub
parent 4c9171e72a
commit 727a60551a
2 changed files with 14 additions and 0 deletions
+11
View File
@@ -148,6 +148,17 @@ export async function deleteChannel(
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
}
const guild = await cacheHandlers.get("guilds", guildID);
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
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 RequestManager.delete(endpoints.CHANNEL_BASE(channelID), { reason });
}
+3
View File
@@ -39,4 +39,7 @@ export enum Errors {
USERNAME_MIN_LENGTH = "USERNAME_MIN_LENGTH",
USERNAME_INVALID_CHARACTER = "USERNAME_INVALID_CHARACTER",
USERNAME_INVALID_USERNAME = "USERNAME_INVALID_USERNAME",
RULES_CHANNEL_CANNOT_BE_DELETED = "RULES_CHANNEL_CANNOT_BE_DELETED",
UPDATES_CHANNEL_CANNOT_BE_DELETED = "UPDATES_CHANNEL_CANNOT_BE_DELETED",
GUILD_NOT_FOUND = "GUILD_NOT_FOUND",
}