diff --git a/src/constants/discord.ts b/src/constants/discord.ts index fe5678c1d..fe9a98da6 100644 --- a/src/constants/discord.ts +++ b/src/constants/discord.ts @@ -51,6 +51,7 @@ export const endpoints = { `${baseEndpoints.BASE_URL}/channels/${id}/messages/${messageID}/crosspost`, // Guild Endpoints + GUILDS: `${baseEndpoints.BASE_URL}/guilds`, GUILD: (id: string) => `${GUILDS_BASE(id)}`, GUILD_AUDIT_LOGS: (id: string) => `${GUILDS_BASE(id)}/audit-logs`, GUILD_BAN: (id: string, userID: string) => diff --git a/src/handlers/guild.ts b/src/handlers/guild.ts index 47a3a9945..3374118d4 100644 --- a/src/handlers/guild.ts +++ b/src/handlers/guild.ts @@ -19,6 +19,7 @@ import type { ChannelCreateOptions, BannedUser, UserPayload, + CreateServerOptions, } from "../types/guild.ts"; import type { RoleData } from "../types/role.ts"; import type { MemberCreatePayload } from "../types/member.ts"; @@ -38,6 +39,11 @@ import { structures } from "../structures/mod.ts"; import { cacheHandlers } from "../controllers/cache.ts"; import { formatImageURL } from "../utils/cdn.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 function createServer(options: CreateServerOptions) { + return RequestManager.post(endpoints.GUILDS, options); +} + /** Gets an array of all the channels ids that are the children of this category. */ export function categoryChildrenIDs(guild: Guild, id: string) { return guild.channels.filter((channel) => channel.parentID === id); @@ -99,7 +105,7 @@ export async function createGuildChannel( name, permission_overwrites: options?.permission_overwrites?.map((perm) => ({ ...perm, - + allow: perm.allow.reduce( (bits, p) => bits |= BigInt(Permissions[p]), BigInt(0), diff --git a/src/types/guild.ts b/src/types/guild.ts index 55cb02533..dda73109a 100644 --- a/src/types/guild.ts +++ b/src/types/guild.ts @@ -583,3 +583,28 @@ export interface FetchMembersOptions { /** Maximum number of members to return that match the query. Default = 0 which will return all members. */ limit?: number; } + +export interface CreateServerOptions { + /** name of the guild (2-100 characters) */ + name: string; + /** voice region id */ + region?: string; + /** guild icon image url or base64 128x128 image for the guild icon */ + icon?: string; + /** verification level */ + verification_level?: number; + /** default message notification level */ + default_message_notifications?: number; + /** explicit content filter level */ + explicit_content_filter?: number; + /** array of role objects new guild roles */ + roles?: RoleData[]; + /** array of partial channel objects new guild's channels */ + channels?: ChannelCreatePayload[]; + /** id for afk channel */ + afk_channel_id?: string; + /** afk timeout in seconds */ + afk_timeout?: number; + /** the id of the channel where guild notices such as welcome messages and boost events are posted */ + system_channel_id?: string; +}