mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
refactor(Guild): Destructure object in guild editing (#8971)
* refactor: simplify guild editing * chore: remove strange rule modification * refactor: destructure more! * refactor: remove pattern, allow `0` bit * refactor: spread Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -740,27 +740,26 @@ class Guild extends AnonymousGuild {
|
|||||||
* @typedef {Object} GuildEditOptions
|
* @typedef {Object} GuildEditOptions
|
||||||
* @property {string} [name] The name of the guild
|
* @property {string} [name] The name of the guild
|
||||||
* @property {?GuildVerificationLevel} [verificationLevel] The verification level of the guild
|
* @property {?GuildVerificationLevel} [verificationLevel] The verification level of the guild
|
||||||
|
* @property {?GuildDefaultMessageNotifications} [defaultMessageNotifications] The default message
|
||||||
|
* notification level of the guild
|
||||||
* @property {?GuildExplicitContentFilter} [explicitContentFilter] The level of the explicit content filter
|
* @property {?GuildExplicitContentFilter} [explicitContentFilter] The level of the explicit content filter
|
||||||
* @property {?VoiceChannelResolvable} [afkChannel] The AFK channel of the guild
|
* @property {?VoiceChannelResolvable} [afkChannel] The AFK channel of the guild
|
||||||
* @property {?TextChannelResolvable} [systemChannel] The system channel of the guild
|
|
||||||
* @property {number} [afkTimeout] The AFK timeout of the guild
|
* @property {number} [afkTimeout] The AFK timeout of the guild
|
||||||
* @property {?(BufferResolvable|Base64Resolvable)} [icon] The icon of the guild
|
* @property {?(BufferResolvable|Base64Resolvable)} [icon] The icon of the guild
|
||||||
* @property {GuildMemberResolvable} [owner] The owner of the guild
|
* @property {GuildMemberResolvable} [owner] The owner of the guild
|
||||||
* @property {?(BufferResolvable|Base64Resolvable)} [splash] The invite splash image of the guild
|
* @property {?(BufferResolvable|Base64Resolvable)} [splash] The invite splash image of the guild
|
||||||
* @property {?(BufferResolvable|Base64Resolvable)} [discoverySplash] The discovery splash image of the guild
|
* @property {?(BufferResolvable|Base64Resolvable)} [discoverySplash] The discovery splash image of the guild
|
||||||
* @property {?(BufferResolvable|Base64Resolvable)} [banner] The banner of the guild
|
* @property {?(BufferResolvable|Base64Resolvable)} [banner] The banner of the guild
|
||||||
* @property {?GuildDefaultMessageNotifications} [defaultMessageNotifications] The default message
|
* @property {?TextChannelResolvable} [systemChannel] The system channel of the guild
|
||||||
* notification level of the guild
|
|
||||||
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
|
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
|
||||||
* @property {?TextChannelResolvable} [rulesChannel] The rules channel of the guild
|
* @property {?TextChannelResolvable} [rulesChannel] The rules channel of the guild
|
||||||
* @property {?TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
|
* @property {?TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
|
||||||
* @property {?string} [preferredLocale] The preferred locale of the guild
|
* @property {?string} [preferredLocale] The preferred locale of the guild
|
||||||
* @property {boolean} [premiumProgressBarEnabled] Whether the guild's premium progress bar is enabled
|
|
||||||
* @property {?string} [description] The discovery description of the guild
|
|
||||||
* @property {GuildFeature[]} [features] The features of the guild
|
* @property {GuildFeature[]} [features] The features of the guild
|
||||||
|
* @property {?string} [description] The discovery description of the guild
|
||||||
|
* @property {boolean} [premiumProgressBarEnabled] Whether the guild's premium progress bar is enabled
|
||||||
* @property {string} [reason] Reason for editing this guild
|
* @property {string} [reason] Reason for editing this guild
|
||||||
*/
|
*/
|
||||||
/* eslint-enable max-len */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data that can be resolved to a Text Channel object. This can be:
|
* Data that can be resolved to a Text Channel object. This can be:
|
||||||
@@ -788,51 +787,52 @@ class Guild extends AnonymousGuild {
|
|||||||
* .then(updated => console.log(`New guild name ${updated}`))
|
* .then(updated => console.log(`New guild name ${updated}`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
async edit(options) {
|
async edit({
|
||||||
const _data = {};
|
verificationLevel,
|
||||||
if (options.name) _data.name = options.name;
|
defaultMessageNotifications,
|
||||||
if (typeof options.verificationLevel !== 'undefined') {
|
explicitContentFilter,
|
||||||
_data.verification_level = options.verificationLevel;
|
afkChannel,
|
||||||
}
|
afkTimeout,
|
||||||
if (typeof options.afkChannel !== 'undefined') {
|
icon,
|
||||||
_data.afk_channel_id = this.client.channels.resolveId(options.afkChannel);
|
owner,
|
||||||
}
|
splash,
|
||||||
if (typeof options.systemChannel !== 'undefined') {
|
discoverySplash,
|
||||||
_data.system_channel_id = this.client.channels.resolveId(options.systemChannel);
|
banner,
|
||||||
}
|
systemChannel,
|
||||||
if (options.afkTimeout) _data.afk_timeout = Number(options.afkTimeout);
|
systemChannelFlags,
|
||||||
if (typeof options.icon !== 'undefined') _data.icon = await DataResolver.resolveImage(options.icon);
|
rulesChannel,
|
||||||
if (options.owner) _data.owner_id = this.client.users.resolveId(options.owner);
|
publicUpdatesChannel,
|
||||||
if (typeof options.splash !== 'undefined') _data.splash = await DataResolver.resolveImage(options.splash);
|
preferredLocale,
|
||||||
if (typeof options.discoverySplash !== 'undefined') {
|
premiumProgressBarEnabled,
|
||||||
_data.discovery_splash = await DataResolver.resolveImage(options.discoverySplash);
|
...options
|
||||||
}
|
}) {
|
||||||
if (typeof options.banner !== 'undefined') _data.banner = await DataResolver.resolveImage(options.banner);
|
const data = await this.client.rest.patch(Routes.guild(this.id), {
|
||||||
if (typeof options.explicitContentFilter !== 'undefined') {
|
body: {
|
||||||
_data.explicit_content_filter = options.explicitContentFilter;
|
...options,
|
||||||
}
|
verification_level: verificationLevel,
|
||||||
if (typeof options.defaultMessageNotifications !== 'undefined') {
|
default_message_notifications: defaultMessageNotifications,
|
||||||
_data.default_message_notifications = options.defaultMessageNotifications;
|
explicit_content_filter: explicitContentFilter,
|
||||||
}
|
afk_channel_id: afkChannel && this.client.channels.resolveId(afkChannel),
|
||||||
if (typeof options.systemChannelFlags !== 'undefined') {
|
afk_timeout: afkTimeout,
|
||||||
_data.system_channel_flags = SystemChannelFlagsBitField.resolve(options.systemChannelFlags);
|
icon: icon && (await DataResolver.resolveImage(icon)),
|
||||||
}
|
owner_id: owner && this.client.users.resolveId(owner),
|
||||||
if (typeof options.rulesChannel !== 'undefined') {
|
splash: splash && (await DataResolver.resolveImage(splash)),
|
||||||
_data.rules_channel_id = this.client.channels.resolveId(options.rulesChannel);
|
discovery_splash: discoverySplash && (await DataResolver.resolveImage(discoverySplash)),
|
||||||
}
|
banner: banner && (await DataResolver.resolveImage(banner)),
|
||||||
if (typeof options.publicUpdatesChannel !== 'undefined') {
|
system_channel_id: systemChannel && this.client.channels.resolveId(systemChannel),
|
||||||
_data.public_updates_channel_id = this.client.channels.resolveId(options.publicUpdatesChannel);
|
system_channel_flags:
|
||||||
}
|
typeof systemChannelFlags === 'undefined'
|
||||||
if (typeof options.features !== 'undefined') {
|
? undefined
|
||||||
_data.features = options.features;
|
: SystemChannelFlagsBitField.resolve(systemChannelFlags),
|
||||||
}
|
rules_channel_id: rulesChannel && this.client.channels.resolveId(rulesChannel),
|
||||||
if (typeof options.description !== 'undefined') {
|
public_updates_channel_id: publicUpdatesChannel && this.client.channels.resolveId(publicUpdatesChannel),
|
||||||
_data.description = options.description;
|
preferred_locale: preferredLocale,
|
||||||
}
|
premium_progress_bar_enabled: premiumProgressBarEnabled,
|
||||||
if (typeof options.preferredLocale !== 'undefined') _data.preferred_locale = options.preferredLocale;
|
},
|
||||||
if ('premiumProgressBarEnabled' in options) _data.premium_progress_bar_enabled = options.premiumProgressBarEnabled;
|
reason: options.reason,
|
||||||
const newData = await this.client.rest.patch(Routes.guild(this.id), { body: _data, reason: options.reason });
|
});
|
||||||
return this.client.actions.GuildUpdate.handle(newData).updated;
|
|
||||||
|
return this.client.actions.GuildUpdate.handle(data).updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -905,7 +905,6 @@ class Guild extends AnonymousGuild {
|
|||||||
return new WelcomeScreen(this, patchData);
|
return new WelcomeScreen(this, patchData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable max-len */
|
|
||||||
/**
|
/**
|
||||||
* Edits the level of the explicit content filter.
|
* Edits the level of the explicit content filter.
|
||||||
* @param {?GuildExplicitContentFilter} explicitContentFilter The new level of the explicit content filter
|
* @param {?GuildExplicitContentFilter} explicitContentFilter The new level of the explicit content filter
|
||||||
@@ -918,14 +917,14 @@ class Guild extends AnonymousGuild {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits the setting of the default message notifications of the guild.
|
* Edits the setting of the default message notifications of the guild.
|
||||||
* @param {?GuildDefaultMessageNotifications} defaultMessageNotifications The new default message notification level of the guild
|
* @param {?GuildDefaultMessageNotifications} defaultMessageNotifications
|
||||||
|
* The new default message notification level of the guild
|
||||||
* @param {string} [reason] Reason for changing the setting of the default message notifications
|
* @param {string} [reason] Reason for changing the setting of the default message notifications
|
||||||
* @returns {Promise<Guild>}
|
* @returns {Promise<Guild>}
|
||||||
*/
|
*/
|
||||||
setDefaultMessageNotifications(defaultMessageNotifications, reason) {
|
setDefaultMessageNotifications(defaultMessageNotifications, reason) {
|
||||||
return this.edit({ defaultMessageNotifications, reason });
|
return this.edit({ defaultMessageNotifications, reason });
|
||||||
}
|
}
|
||||||
/* eslint-enable max-len */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits the flags of the default message notifications of the guild.
|
* Edits the flags of the default message notifications of the guild.
|
||||||
|
|||||||
12
packages/discord.js/typings/index.d.ts
vendored
12
packages/discord.js/typings/index.d.ts
vendored
@@ -5430,23 +5430,23 @@ export interface GuildWidgetSettings {
|
|||||||
export interface GuildEditOptions {
|
export interface GuildEditOptions {
|
||||||
name?: string;
|
name?: string;
|
||||||
verificationLevel?: GuildVerificationLevel | null;
|
verificationLevel?: GuildVerificationLevel | null;
|
||||||
explicitContentFilter?: GuildExplicitContentFilter | null;
|
|
||||||
defaultMessageNotifications?: GuildDefaultMessageNotifications | null;
|
defaultMessageNotifications?: GuildDefaultMessageNotifications | null;
|
||||||
afkChannel?: VoiceChannelResolvable | null;
|
explicitContentFilter?: GuildExplicitContentFilter | null;
|
||||||
systemChannel?: TextChannelResolvable | null;
|
|
||||||
systemChannelFlags?: SystemChannelFlagsResolvable;
|
|
||||||
afkTimeout?: number;
|
afkTimeout?: number;
|
||||||
|
afkChannel?: VoiceChannelResolvable | null;
|
||||||
icon?: BufferResolvable | Base64Resolvable | null;
|
icon?: BufferResolvable | Base64Resolvable | null;
|
||||||
owner?: GuildMemberResolvable;
|
owner?: GuildMemberResolvable;
|
||||||
splash?: BufferResolvable | Base64Resolvable | null;
|
splash?: BufferResolvable | Base64Resolvable | null;
|
||||||
discoverySplash?: BufferResolvable | Base64Resolvable | null;
|
discoverySplash?: BufferResolvable | Base64Resolvable | null;
|
||||||
banner?: BufferResolvable | Base64Resolvable | null;
|
banner?: BufferResolvable | Base64Resolvable | null;
|
||||||
|
systemChannel?: TextChannelResolvable | null;
|
||||||
|
systemChannelFlags?: SystemChannelFlagsResolvable;
|
||||||
rulesChannel?: TextChannelResolvable | null;
|
rulesChannel?: TextChannelResolvable | null;
|
||||||
publicUpdatesChannel?: TextChannelResolvable | null;
|
publicUpdatesChannel?: TextChannelResolvable | null;
|
||||||
preferredLocale?: Locale | null;
|
preferredLocale?: Locale | null;
|
||||||
premiumProgressBarEnabled?: boolean;
|
|
||||||
description?: string | null;
|
|
||||||
features?: `${GuildFeature}`[];
|
features?: `${GuildFeature}`[];
|
||||||
|
description?: string | null;
|
||||||
|
premiumProgressBarEnabled?: boolean;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user