mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 09:50:07 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Bot, Channel, CreateGuildChannel, separateOverwrites } from "../deps.ts";
|
|
|
|
/** Create a copy of a channel */
|
|
export async function cloneChannel(bot: Bot, channel: Channel, reason?: string) {
|
|
if (!channel.guildId) {
|
|
throw new Error(`Cannot clone a channel outside a guild`);
|
|
}
|
|
|
|
const createChannelOptions: CreateGuildChannel = {
|
|
type: channel.type,
|
|
bitrate: channel.bitrate,
|
|
userLimit: channel.userLimit,
|
|
rateLimitPerUser: channel.rateLimitPerUser,
|
|
position: channel.position,
|
|
parentId: channel.parentId,
|
|
nsfw: channel.nsfw,
|
|
name: channel.name!,
|
|
topic: channel.topic || undefined,
|
|
permissionOverwrites: channel.permissionOverwrites.map((overwrite) => {
|
|
const [type, id, allow, deny] = separateOverwrites(overwrite);
|
|
|
|
return {
|
|
id,
|
|
type,
|
|
allow: bot.utils.calculatePermissions(BigInt(allow)),
|
|
deny: bot.utils.calculatePermissions(BigInt(deny)),
|
|
};
|
|
}),
|
|
reason,
|
|
};
|
|
|
|
//Create the channel (also handles permissions)
|
|
return await bot.helpers.createChannel(channel.guildId!, createChannelOptions);
|
|
}
|