mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
Clarify that permission_overwrites can omit allow and deny keys when creating/modifying channel/channel ovewrites
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import type { Channel } from "../../types/channels/channel.ts";
|
|
import { ChannelTypes } from "../../types/channels/channelTypes.ts";
|
|
import type { CreateGuildChannel } from "../../types/guilds/createGuildChannel.ts";
|
|
import type { Bot } from "../../bot.ts";
|
|
|
|
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
|
export async function createChannel(bot: Bot, guildId: bigint, options?: CreateGuildChannel, reason?: string) {
|
|
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
|
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
|
|
|
|
const result = await bot.rest.runMethod<Channel>(
|
|
bot.rest,
|
|
"post",
|
|
bot.constants.endpoints.GUILD_CHANNELS(guildId),
|
|
options
|
|
? {
|
|
name: options.name,
|
|
topic: options.topic,
|
|
bitrate: options.bitrate,
|
|
user_limit: options.userLimit,
|
|
rate_limit_per_user: options.rateLimitPerUser,
|
|
position: options.position,
|
|
parent_id: options.parentId?.toString(),
|
|
nsfw: options.nsfw,
|
|
permission_overwrites: options?.permissionOverwrites?.map((overwrite) => ({
|
|
id: overwrite.id.toString(),
|
|
type: overwrite.type,
|
|
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : null,
|
|
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null,
|
|
})),
|
|
type: options?.type || ChannelTypes.GuildText,
|
|
reason,
|
|
}
|
|
: {},
|
|
);
|
|
|
|
return bot.transformers.channel(bot, { channel: result, guildId });
|
|
}
|