Files
discordeno/helpers/channels/createChannel.ts
Skillz4Killz a0a1554756 refactor: typings using ReturnType (#2105)
* fix: check new types idea

* fix: type errors

* fix: new style

* fix: more cleanup

* fix: more cleanup

* fix: cleanup audit logs

* fix: cleanup stickers

* fix: cleanup integrations

* fix: more cleanup

* fix: organize into 1 place

* fix: few errors

* fix: some broken import fixes

* fix: quite a lot of fixes across the board

* fix: more fixes for broken imports

* fix: more fixes for broken imports

* fix: handler imports

* fix: all remaining import errors

* fix: more errors needing fixes

* fix: clearing up transformers

* fix: few moer types

* fix: more cleanup of extra types

* fix: fmt

* fix: cleanup discordeno file

* Nuke Base Types (#2102)

* fix: cleanup snake stuff

* convert camelCase to snake_case (#2103)

* fix: add camelize

* fix: finalize remaining errors

* fix: imports in test

Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
2022-03-14 22:11:22 -04:00

62 lines
2.3 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { ChannelTypes } from "../../types/shared.ts";
import { DiscordChannel } from "../../types/discord.ts";
import { OverwriteReadable } from "./editChannelOverwrite.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<DiscordChannel>(
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 });
}
export interface CreateGuildChannel {
/** Channel name (1-100 characters) */
name: string;
/** The type of channel */
type?: ChannelTypes;
/** Channel topic (0-1024 characters) */
topic?: string;
/** The bitrate (in bits) of the voice channel (voice only) */
bitrate?: number;
/** The user limit of the voice channel (voice only) */
userLimit?: number;
/** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected */
rateLimitPerUser?: number;
/** Sorting position of the channel */
position?: number;
/** The channel's permission overwrites */
permissionOverwrites?: OverwriteReadable[];
/** Id of the parent category for a channel */
parentId?: bigint;
/** Whether the channel is nsfw */
nsfw?: boolean;
}