Files
discordeno/helpers/guilds/createGuild.ts
Dorian Oszczęda c9659bca4c feat!: Add return types to helper functions. (#2395)
* feat: Add return types to forum channel helpers.

* fix: Use Discord-defined property names. Add `flags` property.

* feat: Add return types to thread channel helpers.

* feat: Add return types to channel helpers.

* feat: Add return types to server discovery helpers.

* misc!: Consistency: 'remove' -> 'delete'.

* misc!: Add `get` keyword to function and file name.

* feat: Add return types to emoji helpers.

* misc!: Remove unused `bot` parameter. Capitalise 'URL'.

* feat: Add return types to guild automod helpers.

* feat: Add return types to guild scheduled event helpers.

* misc!: Consistency: Rename `emojiURL` to `getEmojiURL`.

* feat: Add return types to guild helpers.

* misc!: Consistency: Add 'get' keyword to function and file names.

* feat: Add return types to invite helpers.

* feat: Add return types to integration helpers.

* feat: Add return types to application command helpers.

* feat: Add return types to followup message helpers.

* feat: Add return types to interaction response helpers.

* feat: Add return type to `createInvite()`.

* feat: Add return types to member helpers.

* misc!: Consistency: Add 'get' keyword to function and file names.

* feat: Add return types to message helpers.

* misc!: Consistency: 'remove' -> 'delete'.

* fix: Use `slice()` to prevent unwanted side effects.

* feat: Add return types to miscellaneous helpers.

* misc!: Consistency: Add 'get' keyword to function and file names.

* feat: Add return types to role helpers.

* feat: Add return types to oauth helpers.

* feat: Add return types to template helpers.

* misc!: Consistency: Add 'guild' keyword to name.

* feat: Add return types to voice helpers.

* fix: Name function correctly.

* feat: Add return types to webhook helpers.

* misc!: Consistency: Rename `sendWebhook` to `sendWebhookMessage`.

* misc: Update exports.

* fix: Imports.

* fix: Change return collection key type from `string` to `bigint`. Remove redundant code.

* misc: Remove `undefined` from `runMethod()` return type.

* style: Remove redundant types.

* style: Rename endpoint call result variables to `result` and `results`.

* misc: Reintroduce `bot` as first parameter.

* misc: Adapt tests to changes made to helpers.

* fix: Object being transformed twice.

* style: Improve naming consistency of remaining files.

* misc: `bigint` -> `number`.

* style: Remove explicit `undefined` return.

* style: Remove `void` operator in favour of generic type.

* misc: Add missing `await` keyword.

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>

* style: Make `reason` property optional instead of `undefined`-able.

* misc: Write out properties manually instead of using the spread operator.

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
2022-08-28 07:17:08 -04:00

57 lines
2.2 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { Channel } from "../../transformers/channel.ts";
import { Guild } from "../../transformers/guild.ts";
import { Role } from "../../transformers/role.ts";
import { DiscordGuild } from "../../types/discord.ts";
import {
DefaultMessageNotificationLevels,
ExplicitContentFilterLevels,
SystemChannelFlags,
VerificationLevels,
} from "../../types/shared.ts";
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
export async function createGuild(bot: Bot, options: CreateGuild): Promise<Guild> {
const result = await bot.rest.runMethod<DiscordGuild>(bot.rest, "POST", bot.constants.routes.GUILDS(), {
name: options.name,
afk_channel_id: options.afkChannelId,
afk_timeout: options.afkTimeout,
channels: options.channels,
default_message_notifications: options.defaultMessageNotifications,
explicit_content_filter: options.explicitContentFilter,
icon: options.icon,
roles: options.roles,
system_channel_flags: options.systemChannelFlags,
system_channel_id: options.systemChannelId,
verification_level: options.verificationLevel,
});
return bot.transformers.guild(bot, { guild: result, shardId: 0 });
}
/** https://discord.com/developers/docs/resources/guild#create-guild */
export interface CreateGuild {
/** Name of the guild (1-100 characters) */
name: string;
/** Base64 128x128 image for the guild icon */
icon?: string;
/** Verification level */
verificationLevel?: VerificationLevels;
/** Default message notification level */
defaultMessageNotifications?: DefaultMessageNotificationLevels;
/** Explicit content filter level */
explicitContentFilter?: ExplicitContentFilterLevels;
/** New guild roles (first role is the everyone role) */
roles?: Role[];
/** New guild's channels */
channels?: Partial<Channel>[];
/** Id for afk channel */
afkChannelId?: string;
/** Afk timeout in seconds */
afkTimeout?: number;
/** The id of the channel where guild notices such as welcome messages and boost events are posted */
systemChannelId?: string;
/** System channel flags */
systemChannelFlags?: SystemChannelFlags;
}