From 2e9bfba5f4bcd73193adbf7f59e7e25248521df3 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Sat, 26 Jul 2025 12:25:36 +0100 Subject: [PATCH] fix!: Remove guild creation (#11012) BREAKING CHANGE: Guild creation is no longer possible. --- packages/core/src/api/guild.ts | 13 -- .../discord.js/src/managers/GuildManager.js | 154 ------------------ packages/discord.js/typings/index.d.ts | 41 ----- 3 files changed, 208 deletions(-) diff --git a/packages/core/src/api/guild.ts b/packages/core/src/api/guild.ts index 39e929efc..7ecf6b7be 100644 --- a/packages/core/src/api/guild.ts +++ b/packages/core/src/api/guild.ts @@ -89,9 +89,7 @@ import { type RESTPostAPIGuildStickerResult, type RESTPostAPIGuildTemplatesJSONBody, type RESTPostAPIGuildTemplatesResult, - type RESTPostAPIGuildsJSONBody, type RESTPostAPIGuildsMFAResult, - type RESTPostAPIGuildsResult, type RESTPutAPIGuildBanJSONBody, type RESTPutAPIGuildMemberJSONBody, type RESTPutAPIGuildMemberResult, @@ -148,17 +146,6 @@ export class GuildsAPI { }) as Promise; } - /** - * Creates a guild - * - * @see {@link https://discord.com/developers/docs/resources/guild#create-guild} - * @param body - The guild to create - * @param options - The options for creating the guild - */ - public async create(body: RESTPostAPIGuildsJSONBody, { auth, signal }: Pick = {}) { - return this.rest.post(Routes.guilds(), { auth, body, signal }) as Promise; - } - /** * Edits a guild * diff --git a/packages/discord.js/src/managers/GuildManager.js b/packages/discord.js/src/managers/GuildManager.js index 7453a044c..573429464 100644 --- a/packages/discord.js/src/managers/GuildManager.js +++ b/packages/discord.js/src/managers/GuildManager.js @@ -14,12 +14,8 @@ const { GuildInvite } = require('../structures/GuildInvite.js'); const { GuildMember } = require('../structures/GuildMember.js'); const { OAuth2Guild } = require('../structures/OAuth2Guild.js'); const { Role } = require('../structures/Role.js'); -const { resolveImage } = require('../util/DataResolver.js'); const { Events } = require('../util/Events.js'); -const { PermissionsBitField } = require('../util/PermissionsBitField.js'); -const { SystemChannelFlagsBitField } = require('../util/SystemChannelFlagsBitField.js'); const { _transformAPIIncidentsData } = require('../util/Transformers.js'); -const { resolveColor } = require('../util/Util.js'); const { CachedManager } = require('./CachedManager.js'); let cacheWarningEmitted = false; @@ -60,50 +56,6 @@ class GuildManager extends CachedManager { * @typedef {Guild|GuildChannel|GuildMember|GuildEmoji|Role|Snowflake|Invite} GuildResolvable */ - /** - * Partial data for a Role. - * - * @typedef {Object} PartialRoleData - * @property {Snowflake|number} [id] The role's id, used to set channel overrides. - * This is a placeholder and will be replaced by the API after consumption - * @property {string} [name] The name of the role - * @property {ColorResolvable} [color] The color of the role, either a hex string or a base 10 number - * @property {boolean} [hoist] Whether the role should be hoisted - * @property {number} [position] The position of the role - * @property {PermissionResolvable} [permissions] The permissions of the role - * @property {boolean} [mentionable] Whether the role should be mentionable - */ - - /** - * Partial overwrite data. - * - * @typedef {Object} PartialOverwriteData - * @property {Snowflake|number} id The id of the {@link Role} or {@link User} this overwrite belongs to - * @property {OverwriteType} [type] The type of this overwrite - * @property {PermissionResolvable} [allow] The permissions to allow - * @property {PermissionResolvable} [deny] The permissions to deny - */ - - /** - * Partial data for a Channel. - * - * @typedef {Object} PartialChannelData - * @property {Snowflake|number} [id] The channel's id, used to set its parent. - * This is a placeholder and will be replaced by the API after consumption - * @property {Snowflake|number} [parentId] The parent id for this channel - * @property {ChannelType.GuildText|ChannelType.GuildVoice|ChannelType.GuildCategory} [type] The type of the channel - * @property {string} name The name of the channel - * @property {?string} [topic] The topic of the text channel - * @property {boolean} [nsfw] Whether the channel is NSFW - * @property {number} [bitrate] The bitrate of the voice channel - * @property {number} [userLimit] The user limit of the channel - * @property {?string} [rtcRegion] The RTC region of the channel - * @property {VideoQualityMode} [videoQualityMode] The camera video quality mode of the channel - * @property {PartialOverwriteData[]} [permissionOverwrites] - * Overwrites of the channel - * @property {number} [rateLimitPerUser] The rate limit per user (slowmode) of the channel in seconds - */ - /** * Resolves a {@link GuildResolvable} to a {@link Guild} object. * @@ -150,112 +102,6 @@ class GuildManager extends CachedManager { return super.resolveId(guild); } - /** - * Options used to create a guild. - * - * @typedef {Object} GuildCreateOptions - * @property {string} name The name of the guild - * @property {?(BufferResolvable|Base64Resolvable)} [icon=null] The icon for the guild - * @property {GuildVerificationLevel} [verificationLevel] The verification level for the guild - * @property {GuildDefaultMessageNotifications} [defaultMessageNotifications] The default message notifications - * for the guild - * @property {GuildExplicitContentFilter} [explicitContentFilter] The explicit content filter level for the guild - * @property {PartialRoleData[]} [roles=[]] The roles for this guild, - * @property {PartialChannelData[]} [channels=[]] The channels for this guild - * @property {Snowflake|number} [afkChannelId] The AFK channel's id - * @property {number} [afkTimeout] The AFK timeout in seconds - * the first element of this array is used to change properties of the guild's everyone role. - * @property {Snowflake|number} [systemChannelId] The system channel's id - * @property {SystemChannelFlagsResolvable} [systemChannelFlags] The flags of the system channel - */ - - /** - * Creates a guild. - * This is only available to bots in fewer than 10 guilds. - * - * @param {GuildCreateOptions} options Options for creating the guild - * @returns {Promise} The guild that was created - */ - async create({ - name, - icon = null, - verificationLevel, - defaultMessageNotifications, - explicitContentFilter, - roles = [], - channels = [], - afkChannelId, - afkTimeout, - systemChannelId, - systemChannelFlags, - }) { - const data = await this.client.rest.post(Routes.guilds(), { - body: { - name, - icon: icon && (await resolveImage(icon)), - verification_level: verificationLevel, - default_message_notifications: defaultMessageNotifications, - explicit_content_filter: explicitContentFilter, - roles: roles.map(({ color, permissions, ...options }) => ({ - ...options, - color: color && resolveColor(color), - permissions: permissions === undefined ? undefined : PermissionsBitField.resolve(permissions).toString(), - })), - channels: channels.map( - ({ - parentId, - userLimit, - rtcRegion, - videoQualityMode, - permissionOverwrites, - rateLimitPerUser, - ...options - }) => ({ - ...options, - parent_id: parentId, - user_limit: userLimit, - rtc_region: rtcRegion, - video_quality_mode: videoQualityMode, - permission_overwrites: permissionOverwrites?.map(({ allow, deny, ...permissionOverwriteOptions }) => ({ - ...permissionOverwriteOptions, - allow: allow === undefined ? undefined : PermissionsBitField.resolve(allow).toString(), - deny: deny === undefined ? undefined : PermissionsBitField.resolve(deny).toString(), - })), - rate_limit_per_user: rateLimitPerUser, - }), - ), - afk_channel_id: afkChannelId, - afk_timeout: afkTimeout, - system_channel_id: systemChannelId, - system_channel_flags: - systemChannelFlags === undefined ? undefined : SystemChannelFlagsBitField.resolve(systemChannelFlags), - }, - }); - - return ( - this.client.guilds.cache.get(data.id) ?? - new Promise(resolve => { - const handleGuild = guild => { - if (guild.id === data.id) { - // eslint-disable-next-line no-use-before-define - clearTimeout(timeout); - this.client.decrementMaxListeners(); - resolve(guild); - } - }; - - this.client.incrementMaxListeners(); - this.client.once(Events.GuildCreate, handleGuild); - - const timeout = setTimeout(() => { - this.client.removeListener(Events.GuildCreate, handleGuild); - this.client.decrementMaxListeners(); - resolve(this.client.guilds._add(data)); - }, 10_000).unref(); - }) - ); - } - /** * Options used to fetch a single guild. * diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index b7e9dd722..25814b7d6 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4347,7 +4347,6 @@ export interface FetchSoundboardSoundsOptions { export class GuildManager extends CachedManager { private constructor(client: Client, iterable?: Iterable); - public create(options: GuildCreateOptions): Promise; public fetch(options: FetchGuildOptions | Snowflake): Promise; public fetch(options?: FetchGuildsOptions): Promise>; public fetchSoundboardSounds( @@ -6111,20 +6110,6 @@ export interface GuildChannelOverwriteOptions { type?: OverwriteType; } -export interface GuildCreateOptions { - afkChannelId?: Snowflake | number; - afkTimeout?: number; - channels?: readonly PartialChannelData[]; - defaultMessageNotifications?: GuildDefaultMessageNotifications; - explicitContentFilter?: GuildExplicitContentFilter; - icon?: Base64Resolvable | BufferResolvable | null; - name: string; - roles?: readonly PartialRoleData[]; - systemChannelFlags?: SystemChannelFlagsResolvable; - systemChannelId?: Snowflake | number; - verificationLevel?: GuildVerificationLevel; -} - export interface GuildWidgetSettings { channel: AnnouncementChannel | ForumChannel | MediaChannel | TextChannel | VoiceBasedChannel | null; enabled: boolean; @@ -6788,21 +6773,6 @@ export interface PresenceData { export type PresenceResolvable = Presence | Snowflake | UserResolvable; -export interface PartialChannelData { - bitrate?: number; - id?: Snowflake | number; - name: string; - nsfw?: boolean; - parentId?: Snowflake | number; - permissionOverwrites?: readonly PartialOverwriteData[]; - rateLimitPerUser?: number; - rtcRegion?: string | null; - topic?: string | null; - type?: ChannelType.GuildCategory | ChannelType.GuildText | ChannelType.GuildVoice; - userLimit?: number; - videoQualityMode?: VideoQualityMode; -} - export interface PartialEmoji { animated: boolean; id: Snowflake | undefined; @@ -6863,17 +6833,6 @@ export interface PartialThreadMember extends Partialize {} -export interface PartialOverwriteData { - allow?: PermissionResolvable; - deny?: PermissionResolvable; - id: Snowflake | number; - type?: OverwriteType; -} - -export interface PartialRoleData extends RoleData { - id?: Snowflake | number; -} - export enum Partials { User, Channel,