mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
Suggested changes to cloneChannel
- Removed name check - Added DM channel check
This commit is contained in:
@@ -1,24 +1,22 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { createChannel } from "./create_channel.ts";
|
import { createChannel } from "./create_channel.ts";
|
||||||
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { DiscordenoChannel } from "../../structures/channel.ts";
|
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||||
|
|
||||||
/** Create a copy of a channel */
|
/** Create a copy of a channel */
|
||||||
export async function cloneChannel(channelId: string, reason?: string) {
|
export async function cloneChannel(channelId: string, reason?: string) {
|
||||||
const channelToClone = await cacheHandlers.get(
|
const channelToClone = await cacheHandlers.get("channels", channelId);
|
||||||
"channels",
|
//Return undefined if channel is not cached
|
||||||
channelId
|
|
||||||
);
|
|
||||||
//Return undefined if channel is not cached (unsure about error handling)
|
|
||||||
if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
||||||
|
|
||||||
//If "name" is undefined as specified by types
|
//Check for DM channel
|
||||||
channelToClone.name ??= "new-channel";
|
if (
|
||||||
|
channelToClone.type === DiscordChannelTypes.DM ||
|
||||||
|
channelToClone.type === DiscordChannelTypes.GROUP_DM
|
||||||
|
) {
|
||||||
|
throw new Error(Errors.CHANNEL_NOT_IN_GUILD);
|
||||||
|
}
|
||||||
|
|
||||||
//Create the channel (also handles permissions)
|
//Create the channel (also handles permissions)
|
||||||
return createChannel(
|
return createChannel(channelToClone.guildId!, channelToClone, reason);
|
||||||
channelToClone.guildId!,
|
|
||||||
channelToClone,
|
|
||||||
reason,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user