mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
Add channel cloning
Changes:
- Added function cloneChannel
- Modified createChannel to support cloneChannel
- Added clone(reason) method on channel structure
- Added channel cloning tests
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { createChannel } from "./create_channel.ts";
|
||||
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
||||
import { DiscordenoChannel } from "../../structures/channel.ts";
|
||||
|
||||
/** Create a copy of a channel */
|
||||
export async function cloneChannel(channelId: string, reason?: string) {
|
||||
const channelToClone: DiscordenoChannel | undefined = await cacheHandlers.get(
|
||||
"channels",
|
||||
channelId
|
||||
);
|
||||
//Return undefined if channel is not cached (unsure about error handling)
|
||||
if (!channelToClone) return;
|
||||
|
||||
//If "name" is null or undefined as specified by types
|
||||
channelToClone.name ??= "new-channel";
|
||||
|
||||
//Merge channel data with reason for createChannel options
|
||||
const creationData = {
|
||||
reason,
|
||||
...channelToClone,
|
||||
};
|
||||
//Create the channel (also handles permissions)
|
||||
return createChannel(
|
||||
channelToClone.guildId!,
|
||||
creationData as CreateGuildChannel
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user