mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
refactor: use consistent naming for options (#8901)
* refactor: use consistent naming for options * chore: update param names in typings * chore: update forgotten `data` param * Update packages/discord.js/src/structures/Guild.js Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -68,7 +68,7 @@ class WebhookClient extends BaseClient {
|
||||
/* eslint-disable no-empty-function, valid-jsdoc */
|
||||
/**
|
||||
* Sends a message with this webhook.
|
||||
* @param {string|MessagePayload|WebhookCreateMessageOptions} options The content for the reply
|
||||
* @param {string|MessagePayload|WebhookMessageCreateOptions} options The content for the reply
|
||||
* @returns {Promise<APIMessage>}
|
||||
*/
|
||||
send() {}
|
||||
@@ -84,7 +84,7 @@ class WebhookClient extends BaseClient {
|
||||
/**
|
||||
* Edits a message that was sent by this webhook.
|
||||
* @param {MessageResolvable} message The message to edit
|
||||
* @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide
|
||||
* @param {string|MessagePayload|WebhookMessageEditOptions} options The options to provide
|
||||
* @returns {Promise<APIMessage>} Returns the message edited by this webhook
|
||||
*/
|
||||
editMessage() {}
|
||||
|
||||
@@ -112,14 +112,14 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
* Options used to set permissions for one or more Application Commands in a guild
|
||||
* <warn>Omitting the `command` parameter edits the guild wide permissions
|
||||
* when the manager's `commandId` is `null`</warn>
|
||||
* @typedef {BaseApplicationCommandPermissionsOptions} EditApplicationCommandPermissionsOptions
|
||||
* @typedef {BaseApplicationCommandPermissionsOptions} ApplicationCommandPermissionsEditOptions
|
||||
* @property {ApplicationCommandPermissions[]} permissions The new permissions for the guild or overwrite
|
||||
* @property {string} token The bearer token to use that authorizes the permission edit
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets the permissions for the guild or a command overwrite.
|
||||
* @param {EditApplicationCommandPermissionsOptions} options Options used to set permissions
|
||||
* @param {ApplicationCommandPermissionsEditOptions} options Options used to set permissions
|
||||
* @returns {Promise<ApplicationCommandPermissions[]|Collection<Snowflake, ApplicationCommandPermissions[]>>}
|
||||
* @example
|
||||
* // Set a permission overwrite for a command
|
||||
@@ -179,7 +179,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
|
||||
|
||||
/**
|
||||
* Add permissions to a command.
|
||||
* @param {EditApplicationCommandPermissionsOptions} options Options used to add permissions
|
||||
* @param {ApplicationCommandPermissionsEditOptions} options Options used to add permissions
|
||||
* @returns {Promise<ApplicationCommandPermissions[]>}
|
||||
* @example
|
||||
* // Add a rule to block a role from using a command
|
||||
|
||||
@@ -258,7 +258,7 @@ class GuildChannelManager extends CachedManager {
|
||||
/**
|
||||
* Edits the channel.
|
||||
* @param {GuildChannelResolvable} channel The channel to edit
|
||||
* @param {GuildChannelEditOptions} data Options for editing the channel
|
||||
* @param {GuildChannelEditOptions} options Options for editing the channel
|
||||
* @returns {Promise<GuildChannel>}
|
||||
* @example
|
||||
* // Edit a channel
|
||||
@@ -266,19 +266,19 @@ class GuildChannelManager extends CachedManager {
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(channel, data) {
|
||||
async edit(channel, options) {
|
||||
channel = this.resolve(channel);
|
||||
if (!channel) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'GuildChannelResolvable');
|
||||
|
||||
const parent = data.parent && this.client.channels.resolveId(data.parent);
|
||||
const parent = options.parent && this.client.channels.resolveId(options.parent);
|
||||
|
||||
if (typeof data.position !== 'undefined') {
|
||||
await this.setPosition(channel, data.position, { position: data.position, reason: data.reason });
|
||||
if (typeof options.position !== 'undefined') {
|
||||
await this.setPosition(channel, options.position, { position: options.position, reason: options.reason });
|
||||
}
|
||||
|
||||
let permission_overwrites = data.permissionOverwrites?.map(o => PermissionOverwrites.resolve(o, this.guild));
|
||||
let permission_overwrites = options.permissionOverwrites?.map(o => PermissionOverwrites.resolve(o, this.guild));
|
||||
|
||||
if (data.lockPermissions) {
|
||||
if (options.lockPermissions) {
|
||||
if (parent) {
|
||||
const newParent = this.guild.channels.resolve(parent);
|
||||
if (newParent?.type === ChannelType.GuildCategory) {
|
||||
@@ -295,26 +295,27 @@ class GuildChannelManager extends CachedManager {
|
||||
|
||||
const newData = await this.client.rest.patch(Routes.channel(channel.id), {
|
||||
body: {
|
||||
name: (data.name ?? channel.name).trim(),
|
||||
type: data.type,
|
||||
topic: data.topic,
|
||||
nsfw: data.nsfw,
|
||||
bitrate: data.bitrate ?? channel.bitrate,
|
||||
user_limit: data.userLimit ?? channel.userLimit,
|
||||
rtc_region: 'rtcRegion' in data ? data.rtcRegion : channel.rtcRegion,
|
||||
video_quality_mode: data.videoQualityMode,
|
||||
name: (options.name ?? channel.name).trim(),
|
||||
type: options.type,
|
||||
topic: options.topic,
|
||||
nsfw: options.nsfw,
|
||||
bitrate: options.bitrate ?? channel.bitrate,
|
||||
user_limit: options.userLimit ?? channel.userLimit,
|
||||
rtc_region: 'rtcRegion' in options ? options.rtcRegion : channel.rtcRegion,
|
||||
video_quality_mode: options.videoQualityMode,
|
||||
parent_id: parent,
|
||||
lock_permissions: data.lockPermissions,
|
||||
rate_limit_per_user: data.rateLimitPerUser,
|
||||
default_auto_archive_duration: data.defaultAutoArchiveDuration,
|
||||
lock_permissions: options.lockPermissions,
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
default_auto_archive_duration: options.defaultAutoArchiveDuration,
|
||||
permission_overwrites,
|
||||
available_tags: data.availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
|
||||
default_reaction_emoji: data.defaultReactionEmoji && transformGuildDefaultReaction(data.defaultReactionEmoji),
|
||||
default_thread_rate_limit_per_user: data.defaultThreadRateLimitPerUser,
|
||||
flags: 'flags' in data ? ChannelFlagsBitField.resolve(data.flags) : undefined,
|
||||
default_sort_order: data.defaultSortOrder,
|
||||
available_tags: options.availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
|
||||
default_reaction_emoji:
|
||||
options.defaultReactionEmoji && transformGuildDefaultReaction(options.defaultReactionEmoji),
|
||||
default_thread_rate_limit_per_user: options.defaultThreadRateLimitPerUser,
|
||||
flags: 'flags' in options ? ChannelFlagsBitField.resolve(options.flags) : undefined,
|
||||
default_sort_order: options.defaultSortOrder,
|
||||
},
|
||||
reason: data.reason,
|
||||
reason: options.reason,
|
||||
});
|
||||
|
||||
return this.client.actions.ChannelUpdate.handle(newData).updated;
|
||||
|
||||
@@ -124,19 +124,19 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
|
||||
/**
|
||||
* Edits an emoji.
|
||||
* @param {EmojiResolvable} emoji The Emoji resolvable to edit
|
||||
* @param {GuildEmojiEditData} data The new data for the emoji
|
||||
* @param {GuildEmojiEditOptions} options The options to provide
|
||||
* @returns {Promise<GuildEmoji>}
|
||||
*/
|
||||
async edit(emoji, data) {
|
||||
async edit(emoji, options) {
|
||||
const id = this.resolveId(emoji);
|
||||
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
|
||||
const roles = data.roles?.map(r => this.guild.roles.resolveId(r));
|
||||
const roles = options.roles?.map(r => this.guild.roles.resolveId(r));
|
||||
const newData = await this.client.rest.patch(Routes.guildEmoji(this.guild.id, id), {
|
||||
body: {
|
||||
name: data.name,
|
||||
name: options.name,
|
||||
roles,
|
||||
},
|
||||
reason: data.reason,
|
||||
reason: options.reason,
|
||||
});
|
||||
const existing = this.cache.get(id);
|
||||
if (existing) {
|
||||
|
||||
@@ -167,7 +167,7 @@ class GuildInviteManager extends CachedManager {
|
||||
/**
|
||||
* Create an invite to the guild from the provided channel.
|
||||
* @param {GuildInvitableChannelResolvable} channel The options for creating the invite from a channel.
|
||||
* @param {CreateInviteOptions} [options={}] The options for creating the invite from a channel.
|
||||
* @param {InviteCreateOptions} [options={}] The options for creating the invite from a channel.
|
||||
* @returns {Promise<Invite>}
|
||||
* @example
|
||||
* // Create an invite to a selected channel
|
||||
|
||||
@@ -270,7 +270,7 @@ class GuildMemberManager extends CachedManager {
|
||||
|
||||
/**
|
||||
* The data for editing a guild member.
|
||||
* @typedef {Object} GuildMemberEditData
|
||||
* @typedef {Object} GuildMemberEditOptions
|
||||
* @property {?string} [nick] The nickname to set for the member
|
||||
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles or role ids to apply
|
||||
* @property {boolean} [mute] Whether or not the member should be muted
|
||||
@@ -286,43 +286,43 @@ class GuildMemberManager extends CachedManager {
|
||||
* Edits a member of the guild.
|
||||
* <info>The user must be a member of the guild</info>
|
||||
* @param {UserResolvable} user The member to edit
|
||||
* @param {GuildMemberEditData} data The data to edit the member with
|
||||
* @param {GuildMemberEditOptions} options The options to provide
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
async edit(user, { reason, ...data }) {
|
||||
async edit(user, { reason, ...options }) {
|
||||
const id = this.client.users.resolveId(user);
|
||||
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable');
|
||||
|
||||
if (data.channel) {
|
||||
data.channel = this.guild.channels.resolve(data.channel);
|
||||
if (!(data.channel instanceof BaseGuildVoiceChannel)) {
|
||||
if (options.channel) {
|
||||
options.channel = this.guild.channels.resolve(options.channel);
|
||||
if (!(options.channel instanceof BaseGuildVoiceChannel)) {
|
||||
throw new DiscordjsError(ErrorCodes.GuildVoiceChannelResolve);
|
||||
}
|
||||
data.channel_id = data.channel.id;
|
||||
data.channel = undefined;
|
||||
} else if (data.channel === null) {
|
||||
data.channel_id = null;
|
||||
data.channel = undefined;
|
||||
options.channel_id = options.channel.id;
|
||||
options.channel = undefined;
|
||||
} else if (options.channel === null) {
|
||||
options.channel_id = null;
|
||||
options.channel = undefined;
|
||||
}
|
||||
data.roles &&= data.roles.map(role => (role instanceof Role ? role.id : role));
|
||||
options.roles &&= options.roles.map(role => (role instanceof Role ? role.id : role));
|
||||
|
||||
if (typeof data.communicationDisabledUntil !== 'undefined') {
|
||||
data.communication_disabled_until =
|
||||
if (typeof options.communicationDisabledUntil !== 'undefined') {
|
||||
options.communication_disabled_until =
|
||||
// eslint-disable-next-line eqeqeq
|
||||
data.communicationDisabledUntil != null
|
||||
? new Date(data.communicationDisabledUntil).toISOString()
|
||||
: data.communicationDisabledUntil;
|
||||
options.communicationDisabledUntil != null
|
||||
? new Date(options.communicationDisabledUntil).toISOString()
|
||||
: options.communicationDisabledUntil;
|
||||
}
|
||||
|
||||
let endpoint;
|
||||
if (id === this.client.user.id) {
|
||||
const keys = Object.keys(data);
|
||||
const keys = Object.keys(options);
|
||||
if (keys.length === 1 && keys[0] === 'nick') endpoint = Routes.guildMember(this.guild.id);
|
||||
else endpoint = Routes.guildMember(this.guild.id, id);
|
||||
} else {
|
||||
endpoint = Routes.guildMember(this.guild.id, id);
|
||||
}
|
||||
const d = await this.client.rest.patch(endpoint, { body: data, reason });
|
||||
const d = await this.client.rest.patch(endpoint, { body: options, reason });
|
||||
|
||||
const clone = this.cache.get(id)?._clone();
|
||||
clone?._patch(d);
|
||||
|
||||
@@ -101,16 +101,16 @@ class GuildStickerManager extends CachedManager {
|
||||
/**
|
||||
* Edits a sticker.
|
||||
* @param {StickerResolvable} sticker The sticker to edit
|
||||
* @param {GuildStickerEditData} [data={}] The new data for the sticker
|
||||
* @param {GuildStickerEditOptions} [options={}] The new data for the sticker
|
||||
* @returns {Promise<Sticker>}
|
||||
*/
|
||||
async edit(sticker, data = {}) {
|
||||
async edit(sticker, options = {}) {
|
||||
const stickerId = this.resolveId(sticker);
|
||||
if (!stickerId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'sticker', 'StickerResolvable');
|
||||
|
||||
const d = await this.client.rest.patch(Routes.guildSticker(this.guild.id, stickerId), {
|
||||
body: data,
|
||||
reason: data.reason,
|
||||
body: options,
|
||||
reason: options.reason,
|
||||
});
|
||||
|
||||
const existing = this.cache.get(stickerId);
|
||||
|
||||
@@ -100,7 +100,7 @@ class RoleManager extends CachedManager {
|
||||
|
||||
/**
|
||||
* Options used to create a new role.
|
||||
* @typedef {Object} CreateRoleOptions
|
||||
* @typedef {Object} RoleCreateOptions
|
||||
* @property {string} [name] The name of the new role
|
||||
* @property {ColorResolvable} [color] The data to create the role with
|
||||
* @property {boolean} [hoist] Whether or not the new role should be hoisted
|
||||
@@ -117,7 +117,7 @@ class RoleManager extends CachedManager {
|
||||
/**
|
||||
* Creates a new role in the guild with given information.
|
||||
* <warn>The position will silently reset to 1 if an invalid one is provided, or none.</warn>
|
||||
* @param {CreateRoleOptions} [options] Options for creating the new role
|
||||
* @param {RoleCreateOptions} [options] Options for creating the new role
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
* // Create a new role
|
||||
@@ -166,14 +166,14 @@ class RoleManager extends CachedManager {
|
||||
|
||||
/**
|
||||
* Options for editing a role
|
||||
* @typedef {RoleData} EditRoleOptions
|
||||
* @typedef {RoleData} RoleEditOptions
|
||||
* @property {string} [reason] The reason for editing this role
|
||||
*/
|
||||
|
||||
/**
|
||||
* Edits a role of the guild.
|
||||
* @param {RoleResolvable} role The role to edit
|
||||
* @param {EditRoleOptions} data The new data for the role
|
||||
* @param {RoleEditOptions} options The options to provide
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
* // Edit a role
|
||||
@@ -181,15 +181,15 @@ class RoleManager extends CachedManager {
|
||||
* .then(updated => console.log(`Edited role name to ${updated.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(role, data) {
|
||||
async edit(role, options) {
|
||||
role = this.resolve(role);
|
||||
if (!role) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'RoleResolvable');
|
||||
|
||||
if (typeof data.position === 'number') {
|
||||
await this.setPosition(role, data.position, { reason: data.reason });
|
||||
if (typeof options.position === 'number') {
|
||||
await this.setPosition(role, options.position, { reason: options.reason });
|
||||
}
|
||||
|
||||
let icon = data.icon;
|
||||
let icon = options.icon;
|
||||
if (icon) {
|
||||
const guildEmojiURL = this.guild.emojis.resolve(icon)?.url;
|
||||
icon = guildEmojiURL ? await DataResolver.resolveImage(guildEmojiURL) : await DataResolver.resolveImage(icon);
|
||||
@@ -197,16 +197,17 @@ class RoleManager extends CachedManager {
|
||||
}
|
||||
|
||||
const body = {
|
||||
name: data.name,
|
||||
color: typeof data.color === 'undefined' ? undefined : resolveColor(data.color),
|
||||
hoist: data.hoist,
|
||||
permissions: typeof data.permissions === 'undefined' ? undefined : new PermissionsBitField(data.permissions),
|
||||
mentionable: data.mentionable,
|
||||
name: options.name,
|
||||
color: typeof options.color === 'undefined' ? undefined : resolveColor(options.color),
|
||||
hoist: options.hoist,
|
||||
permissions:
|
||||
typeof options.permissions === 'undefined' ? undefined : new PermissionsBitField(options.permissions),
|
||||
mentionable: options.mentionable,
|
||||
icon,
|
||||
unicode_emoji: data.unicodeEmoji,
|
||||
unicode_emoji: options.unicodeEmoji,
|
||||
};
|
||||
|
||||
const d = await this.client.rest.patch(Routes.guildRole(this.guild.id, role.id), { body, reason: data.reason });
|
||||
const d = await this.client.rest.patch(Routes.guildRole(this.guild.id, role.id), { body, reason: options.reason });
|
||||
|
||||
const clone = role._clone();
|
||||
clone._patch(d);
|
||||
|
||||
@@ -125,7 +125,7 @@ class BaseGuildTextChannel extends GuildChannel {
|
||||
|
||||
/**
|
||||
* Options used to create an invite to a guild channel.
|
||||
* @typedef {Object} CreateInviteOptions
|
||||
* @typedef {Object} InviteCreateOptions
|
||||
* @property {boolean} [temporary] Whether members that joined via the invite should be automatically
|
||||
* kicked after 24 hours if they have not yet received a role
|
||||
* @property {number} [maxAge] How long the invite should last (in seconds, 0 for forever)
|
||||
@@ -142,7 +142,7 @@ class BaseGuildTextChannel extends GuildChannel {
|
||||
|
||||
/**
|
||||
* Creates an invite to this guild channel.
|
||||
* @param {CreateInviteOptions} [options={}] The options for creating the invite
|
||||
* @param {InviteCreateOptions} [options={}] The options for creating the invite
|
||||
* @returns {Promise<Invite>}
|
||||
* @example
|
||||
* // Create an invite to a channel
|
||||
|
||||
@@ -98,7 +98,7 @@ class BaseGuildVoiceChannel extends GuildChannel {
|
||||
|
||||
/**
|
||||
* Creates an invite to this guild channel.
|
||||
* @param {CreateInviteOptions} [options={}] The options for creating the invite
|
||||
* @param {InviteCreateOptions} [options={}] The options for creating the invite
|
||||
* @returns {Promise<Invite>}
|
||||
* @example
|
||||
* // Create an invite to a channel
|
||||
|
||||
@@ -44,19 +44,19 @@ class ClientUser extends User {
|
||||
|
||||
/**
|
||||
* Data used to edit the logged in client
|
||||
* @typedef {Object} ClientUserEditData
|
||||
* @typedef {Object} ClientUserEditOptions
|
||||
* @property {string} [username] The new username
|
||||
* @property {?(BufferResolvable|Base64Resolvable)} [avatar] The new avatar
|
||||
*/
|
||||
|
||||
/**
|
||||
* Edits the logged in client.
|
||||
* @param {ClientUserEditData} data The new data
|
||||
* @param {ClientUserEditOptions} options The options to provide
|
||||
* @returns {Promise<ClientUser>}
|
||||
*/
|
||||
async edit(data) {
|
||||
if (typeof data.avatar !== 'undefined') data.avatar = await DataResolver.resolveImage(data.avatar);
|
||||
const newData = await this.client.rest.patch(Routes.user(), { body: data });
|
||||
async edit(options) {
|
||||
if (typeof options.avatar !== 'undefined') options.avatar = await DataResolver.resolveImage(options.avatar);
|
||||
const newData = await this.client.rest.patch(Routes.user(), { body: options });
|
||||
this.client.token = newData.token;
|
||||
this.client.rest.setToken(newData.token);
|
||||
const { updated } = this.client.actions.UserUpdate.handle(newData);
|
||||
|
||||
@@ -168,7 +168,7 @@ class ForumChannel extends GuildChannel {
|
||||
|
||||
/**
|
||||
* Creates an invite to this guild channel.
|
||||
* @param {CreateInviteOptions} [options={}] The options for creating the invite
|
||||
* @param {InviteCreateOptions} [options={}] The options for creating the invite
|
||||
* @returns {Promise<Invite>}
|
||||
* @example
|
||||
* // Create an invite to a channel
|
||||
|
||||
@@ -737,7 +737,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* The data for editing a guild.
|
||||
* @typedef {Object} GuildEditData
|
||||
* @typedef {Object} GuildEditOptions
|
||||
* @property {string} [name] The name of the guild
|
||||
* @property {?GuildVerificationLevel} [verificationLevel] The verification level of the guild
|
||||
* @property {?GuildExplicitContentFilter} [explicitContentFilter] The level of the explicit content filter
|
||||
@@ -778,7 +778,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Updates the guild with new information - e.g. a new name.
|
||||
* @param {GuildEditData} data The data to update the guild with
|
||||
* @param {GuildEditOptions} options The options to provide
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* // Set the guild name
|
||||
@@ -788,50 +788,50 @@ class Guild extends AnonymousGuild {
|
||||
* .then(updated => console.log(`New guild name ${updated}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(data) {
|
||||
async edit(options) {
|
||||
const _data = {};
|
||||
if (data.name) _data.name = data.name;
|
||||
if (typeof data.verificationLevel !== 'undefined') {
|
||||
_data.verification_level = data.verificationLevel;
|
||||
if (options.name) _data.name = options.name;
|
||||
if (typeof options.verificationLevel !== 'undefined') {
|
||||
_data.verification_level = options.verificationLevel;
|
||||
}
|
||||
if (typeof data.afkChannel !== 'undefined') {
|
||||
_data.afk_channel_id = this.client.channels.resolveId(data.afkChannel);
|
||||
if (typeof options.afkChannel !== 'undefined') {
|
||||
_data.afk_channel_id = this.client.channels.resolveId(options.afkChannel);
|
||||
}
|
||||
if (typeof data.systemChannel !== 'undefined') {
|
||||
_data.system_channel_id = this.client.channels.resolveId(data.systemChannel);
|
||||
if (typeof options.systemChannel !== 'undefined') {
|
||||
_data.system_channel_id = this.client.channels.resolveId(options.systemChannel);
|
||||
}
|
||||
if (data.afkTimeout) _data.afk_timeout = Number(data.afkTimeout);
|
||||
if (typeof data.icon !== 'undefined') _data.icon = await DataResolver.resolveImage(data.icon);
|
||||
if (data.owner) _data.owner_id = this.client.users.resolveId(data.owner);
|
||||
if (typeof data.splash !== 'undefined') _data.splash = await DataResolver.resolveImage(data.splash);
|
||||
if (typeof data.discoverySplash !== 'undefined') {
|
||||
_data.discovery_splash = await DataResolver.resolveImage(data.discoverySplash);
|
||||
if (options.afkTimeout) _data.afk_timeout = Number(options.afkTimeout);
|
||||
if (typeof options.icon !== 'undefined') _data.icon = await DataResolver.resolveImage(options.icon);
|
||||
if (options.owner) _data.owner_id = this.client.users.resolveId(options.owner);
|
||||
if (typeof options.splash !== 'undefined') _data.splash = await DataResolver.resolveImage(options.splash);
|
||||
if (typeof options.discoverySplash !== 'undefined') {
|
||||
_data.discovery_splash = await DataResolver.resolveImage(options.discoverySplash);
|
||||
}
|
||||
if (typeof data.banner !== 'undefined') _data.banner = await DataResolver.resolveImage(data.banner);
|
||||
if (typeof data.explicitContentFilter !== 'undefined') {
|
||||
_data.explicit_content_filter = data.explicitContentFilter;
|
||||
if (typeof options.banner !== 'undefined') _data.banner = await DataResolver.resolveImage(options.banner);
|
||||
if (typeof options.explicitContentFilter !== 'undefined') {
|
||||
_data.explicit_content_filter = options.explicitContentFilter;
|
||||
}
|
||||
if (typeof data.defaultMessageNotifications !== 'undefined') {
|
||||
_data.default_message_notifications = data.defaultMessageNotifications;
|
||||
if (typeof options.defaultMessageNotifications !== 'undefined') {
|
||||
_data.default_message_notifications = options.defaultMessageNotifications;
|
||||
}
|
||||
if (typeof data.systemChannelFlags !== 'undefined') {
|
||||
_data.system_channel_flags = SystemChannelFlagsBitField.resolve(data.systemChannelFlags);
|
||||
if (typeof options.systemChannelFlags !== 'undefined') {
|
||||
_data.system_channel_flags = SystemChannelFlagsBitField.resolve(options.systemChannelFlags);
|
||||
}
|
||||
if (typeof data.rulesChannel !== 'undefined') {
|
||||
_data.rules_channel_id = this.client.channels.resolveId(data.rulesChannel);
|
||||
if (typeof options.rulesChannel !== 'undefined') {
|
||||
_data.rules_channel_id = this.client.channels.resolveId(options.rulesChannel);
|
||||
}
|
||||
if (typeof data.publicUpdatesChannel !== 'undefined') {
|
||||
_data.public_updates_channel_id = this.client.channels.resolveId(data.publicUpdatesChannel);
|
||||
if (typeof options.publicUpdatesChannel !== 'undefined') {
|
||||
_data.public_updates_channel_id = this.client.channels.resolveId(options.publicUpdatesChannel);
|
||||
}
|
||||
if (typeof data.features !== 'undefined') {
|
||||
_data.features = data.features;
|
||||
if (typeof options.features !== 'undefined') {
|
||||
_data.features = options.features;
|
||||
}
|
||||
if (typeof data.description !== 'undefined') {
|
||||
_data.description = data.description;
|
||||
if (typeof options.description !== 'undefined') {
|
||||
_data.description = options.description;
|
||||
}
|
||||
if (typeof data.preferredLocale !== 'undefined') _data.preferred_locale = data.preferredLocale;
|
||||
if ('premiumProgressBarEnabled' in data) _data.premium_progress_bar_enabled = data.premiumProgressBarEnabled;
|
||||
const newData = await this.client.rest.patch(Routes.guild(this.id), { body: _data, reason: data.reason });
|
||||
if (typeof options.preferredLocale !== 'undefined') _data.preferred_locale = options.preferredLocale;
|
||||
if ('premiumProgressBarEnabled' in options) _data.premium_progress_bar_enabled = options.premiumProgressBarEnabled;
|
||||
const newData = await this.client.rest.patch(Routes.guild(this.id), { body: _data, reason: options.reason });
|
||||
return this.client.actions.GuildUpdate.handle(newData).updated;
|
||||
}
|
||||
|
||||
@@ -845,7 +845,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Welcome screen edit data
|
||||
* @typedef {Object} WelcomeScreenEditData
|
||||
* @typedef {Object} WelcomeScreenEditOptions
|
||||
* @property {boolean} [enabled] Whether the welcome screen is enabled
|
||||
* @property {string} [description] The description for the welcome screen
|
||||
* @property {WelcomeChannelData[]} [welcomeChannels] The welcome channel data for the welcome screen
|
||||
@@ -869,7 +869,7 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
/**
|
||||
* Updates the guild's welcome screen
|
||||
* @param {WelcomeScreenEditData} data Data to edit the welcome screen with
|
||||
* @param {WelcomeScreenEditOptions} options The options to provide
|
||||
* @returns {Promise<WelcomeScreen>}
|
||||
* @example
|
||||
* guild.editWelcomeScreen({
|
||||
@@ -883,8 +883,8 @@ class Guild extends AnonymousGuild {
|
||||
* ],
|
||||
* })
|
||||
*/
|
||||
async editWelcomeScreen(data) {
|
||||
const { enabled, description, welcomeChannels } = data;
|
||||
async editWelcomeScreen(options) {
|
||||
const { enabled, description, welcomeChannels } = options;
|
||||
const welcome_channels = welcomeChannels?.map(welcomeChannelData => {
|
||||
const emoji = this.emojis.resolve(welcomeChannelData.emoji);
|
||||
return {
|
||||
|
||||
@@ -268,7 +268,7 @@ class GuildChannel extends BaseChannel {
|
||||
|
||||
/**
|
||||
* Edits the channel.
|
||||
* @param {GuildChannelEditOptions} data The new data for the channel
|
||||
* @param {GuildChannelEditOptions} options The options to provide
|
||||
* @returns {Promise<GuildChannel>}
|
||||
* @example
|
||||
* // Edit a channel
|
||||
@@ -276,8 +276,8 @@ class GuildChannel extends BaseChannel {
|
||||
* .then(console.log)
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(data) {
|
||||
return this.guild.channels.edit(this, data);
|
||||
edit(options) {
|
||||
return this.guild.channels.edit(this, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,7 +78,7 @@ class GuildEmoji extends BaseGuildEmoji {
|
||||
|
||||
/**
|
||||
* Data for editing an emoji.
|
||||
* @typedef {Object} GuildEmojiEditData
|
||||
* @typedef {Object} GuildEmojiEditOptions
|
||||
* @property {string} [name] The name of the emoji
|
||||
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] Roles to restrict emoji to
|
||||
* @property {string} [reason] Reason for editing this emoji
|
||||
@@ -86,7 +86,7 @@ class GuildEmoji extends BaseGuildEmoji {
|
||||
|
||||
/**
|
||||
* Edits the emoji.
|
||||
* @param {GuildEmojiEditData} data The new data for the emoji
|
||||
* @param {GuildEmojiEditOptions} options The options to provide
|
||||
* @returns {Promise<GuildEmoji>}
|
||||
* @example
|
||||
* // Edit an emoji
|
||||
@@ -94,8 +94,8 @@ class GuildEmoji extends BaseGuildEmoji {
|
||||
* .then(e => console.log(`Edited emoji ${e}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(data) {
|
||||
return this.guild.emojis.edit(this.id, data);
|
||||
edit(options) {
|
||||
return this.guild.emojis.edit(this.id, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -307,11 +307,11 @@ class GuildMember extends Base {
|
||||
|
||||
/**
|
||||
* Edits this member.
|
||||
* @param {GuildMemberEditData} data The data to edit the member with
|
||||
* @param {GuildMemberEditOptions} options The options to provide
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
edit(data) {
|
||||
return this.guild.members.edit(this, data);
|
||||
edit(options) {
|
||||
return this.guild.members.edit(this, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -240,7 +240,7 @@ class GuildScheduledEvent extends Base {
|
||||
|
||||
/**
|
||||
* Options used to create an invite URL to a {@link GuildScheduledEvent}
|
||||
* @typedef {CreateInviteOptions} CreateGuildScheduledEventInviteURLOptions
|
||||
* @typedef {InviteCreateOptions} GuildScheduledEventInviteURLCreateOptions
|
||||
* @property {GuildInvitableChannelResolvable} [channel] The channel to create the invite in.
|
||||
* <warn>This is required when the `entityType` of `GuildScheduledEvent` is
|
||||
* {@link GuildScheduledEventEntityType.External}, gets ignored otherwise</warn>
|
||||
@@ -248,7 +248,7 @@ class GuildScheduledEvent extends Base {
|
||||
|
||||
/**
|
||||
* Creates an invite URL to this guild scheduled event.
|
||||
* @param {CreateGuildScheduledEventInviteURLOptions} [options] The options to create the invite
|
||||
* @param {GuildScheduledEventInviteURLCreateOptions} [options] The options to create the invite
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async createInviteURL(options) {
|
||||
|
||||
@@ -155,14 +155,14 @@ class GuildTemplate extends Base {
|
||||
|
||||
/**
|
||||
* Options used to edit a guild template.
|
||||
* @typedef {Object} EditGuildTemplateOptions
|
||||
* @typedef {Object} GuildTemplateEditOptions
|
||||
* @property {string} [name] The name of this template
|
||||
* @property {string} [description] The description of this template
|
||||
*/
|
||||
|
||||
/**
|
||||
* Updates the metadata of this template.
|
||||
* @param {EditGuildTemplateOptions} [options] Options for editing the template
|
||||
* @param {GuildTemplateEditOptions} [options] Options for editing the template
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
*/
|
||||
async edit({ name, description } = {}) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class InteractionWebhook {
|
||||
/**
|
||||
* Edits a message that was sent by this webhook.
|
||||
* @param {MessageResolvable|'@original'} message The message to edit
|
||||
* @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide
|
||||
* @param {string|MessagePayload|WebhookMessageEditOptions} options The options to provide
|
||||
* @returns {Promise<Message>} Returns the message edited by this webhook
|
||||
*/
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ module.exports = MessagePayload;
|
||||
|
||||
/**
|
||||
* A possible payload option.
|
||||
* @typedef {MessageCreateOptions|MessageEditOptions|WebhookCreateMessageOptions|WebhookEditMessageOptions|
|
||||
* @typedef {MessageCreateOptions|MessageEditOptions|WebhookMessageCreateOptions|WebhookMessageEditOptions|
|
||||
* InteractionReplyOptions|InteractionUpdateOptions} MessagePayloadOption
|
||||
*/
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ class Role extends Base {
|
||||
|
||||
/**
|
||||
* Edits the role.
|
||||
* @param {EditRoleOptions} data The new data for the role
|
||||
* @param {RoleEditOptions} options The options to provide
|
||||
* @returns {Promise<Role>}
|
||||
* @example
|
||||
* // Edit a role
|
||||
@@ -215,8 +215,8 @@ class Role extends Base {
|
||||
* .then(updated => console.log(`Edited role name to ${updated.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(data) {
|
||||
return this.guild.roles.edit(this, data);
|
||||
edit(options) {
|
||||
return this.guild.roles.edit(this, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -197,7 +197,7 @@ class Sticker extends Base {
|
||||
|
||||
/**
|
||||
* Data for editing a sticker.
|
||||
* @typedef {Object} GuildStickerEditData
|
||||
* @typedef {Object} GuildStickerEditOptions
|
||||
* @property {string} [name] The name of the sticker
|
||||
* @property {?string} [description] The description of the sticker
|
||||
* @property {string} [tags] The Discord name of a unicode emoji representing the sticker's expression
|
||||
@@ -206,7 +206,7 @@ class Sticker extends Base {
|
||||
|
||||
/**
|
||||
* Edits the sticker.
|
||||
* @param {GuildStickerEditData} data The new data for the sticker
|
||||
* @param {GuildStickerEditOptions} options The options to provide
|
||||
* @returns {Promise<Sticker>}
|
||||
* @example
|
||||
* // Update the name of a sticker
|
||||
@@ -214,8 +214,8 @@ class Sticker extends Base {
|
||||
* .then(s => console.log(`Updated the name of the sticker to ${s.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(data) {
|
||||
return this.guild.stickers.edit(this, data);
|
||||
edit(options) {
|
||||
return this.guild.stickers.edit(this, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -316,7 +316,7 @@ class ThreadChannel extends BaseChannel {
|
||||
|
||||
/**
|
||||
* The options used to edit a thread channel
|
||||
* @typedef {Object} ThreadEditData
|
||||
* @typedef {Object} ThreadEditOptions
|
||||
* @property {string} [name] The new name for the thread
|
||||
* @property {boolean} [archived] Whether the thread is archived
|
||||
* @property {ThreadAutoArchiveDuration} [autoArchiveDuration] The amount of time after which the thread
|
||||
@@ -332,7 +332,7 @@ class ThreadChannel extends BaseChannel {
|
||||
|
||||
/**
|
||||
* Edits this thread.
|
||||
* @param {ThreadEditData} data The new data for this thread
|
||||
* @param {ThreadEditOptions} options The options to provide
|
||||
* @returns {Promise<ThreadChannel>}
|
||||
* @example
|
||||
* // Edit a thread
|
||||
@@ -340,19 +340,19 @@ class ThreadChannel extends BaseChannel {
|
||||
* .then(editedThread => console.log(editedThread))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async edit(data) {
|
||||
async edit(options) {
|
||||
const newData = await this.client.rest.patch(Routes.channel(this.id), {
|
||||
body: {
|
||||
name: (data.name ?? this.name).trim(),
|
||||
archived: data.archived,
|
||||
auto_archive_duration: data.autoArchiveDuration,
|
||||
rate_limit_per_user: data.rateLimitPerUser,
|
||||
locked: data.locked,
|
||||
invitable: this.type === ChannelType.PrivateThread ? data.invitable : undefined,
|
||||
applied_tags: data.appliedTags,
|
||||
flags: 'flags' in data ? ChannelFlagsBitField.resolve(data.flags) : undefined,
|
||||
name: (options.name ?? this.name).trim(),
|
||||
archived: options.archived,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
locked: options.locked,
|
||||
invitable: this.type === ChannelType.PrivateThread ? options.invitable : undefined,
|
||||
applied_tags: options.appliedTags,
|
||||
flags: 'flags' in options ? ChannelFlagsBitField.resolve(options.flags) : undefined,
|
||||
},
|
||||
reason: data.reason,
|
||||
reason: options.reason,
|
||||
});
|
||||
|
||||
return this.client.actions.ChannelUpdate.handle(newData).updated;
|
||||
|
||||
@@ -208,7 +208,7 @@ class VoiceState extends Base {
|
||||
|
||||
/**
|
||||
* Data to edit the logged in user's own voice state with, when in a stage channel
|
||||
* @typedef {Object} VoiceStateEditData
|
||||
* @typedef {Object} VoiceStateEditOptions
|
||||
* @property {boolean} [requestToSpeak] Whether or not the client is requesting to become a speaker.
|
||||
* <info>Only available to the logged in user's own voice state.</info>
|
||||
* @property {boolean} [suppressed] Whether or not the user should be suppressed.
|
||||
@@ -216,35 +216,35 @@ class VoiceState extends Base {
|
||||
|
||||
/**
|
||||
* Edits this voice state. Currently only available when in a stage channel
|
||||
* @param {VoiceStateEditData} data The data to edit the voice state with
|
||||
* @param {VoiceStateEditOptions} options The options to provide
|
||||
* @returns {Promise<VoiceState>}
|
||||
*/
|
||||
async edit(data) {
|
||||
async edit(options) {
|
||||
if (this.channel?.type !== ChannelType.GuildStageVoice) throw new DiscordjsError(ErrorCodes.VoiceNotStageChannel);
|
||||
|
||||
const target = this.client.user.id === this.id ? '@me' : this.id;
|
||||
|
||||
if (target !== '@me' && typeof data.requestToSpeak !== 'undefined') {
|
||||
if (target !== '@me' && typeof options.requestToSpeak !== 'undefined') {
|
||||
throw new DiscordjsError(ErrorCodes.VoiceStateNotOwn);
|
||||
}
|
||||
|
||||
if (!['boolean', 'undefined'].includes(typeof data.requestToSpeak)) {
|
||||
if (!['boolean', 'undefined'].includes(typeof options.requestToSpeak)) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.VoiceStateInvalidType, 'requestToSpeak');
|
||||
}
|
||||
|
||||
if (!['boolean', 'undefined'].includes(typeof data.suppressed)) {
|
||||
if (!['boolean', 'undefined'].includes(typeof options.suppressed)) {
|
||||
throw new DiscordjsTypeError(ErrorCodes.VoiceStateInvalidType, 'suppressed');
|
||||
}
|
||||
|
||||
await this.client.rest.patch(Routes.guildVoiceState(this.guild.id, target), {
|
||||
body: {
|
||||
channel_id: this.channelId,
|
||||
request_to_speak_timestamp: data.requestToSpeak
|
||||
request_to_speak_timestamp: options.requestToSpeak
|
||||
? new Date().toISOString()
|
||||
: data.requestToSpeak === false
|
||||
: options.requestToSpeak === false
|
||||
? null
|
||||
: undefined,
|
||||
suppress: data.suppressed,
|
||||
suppress: options.suppressed,
|
||||
},
|
||||
});
|
||||
return this;
|
||||
|
||||
@@ -126,7 +126,7 @@ class Webhook {
|
||||
|
||||
/**
|
||||
* Options that can be passed into send.
|
||||
* @typedef {BaseMessageOptions} WebhookCreateMessageOptions
|
||||
* @typedef {BaseMessageOptions} WebhookMessageCreateOptions
|
||||
* @property {boolean} [tts=false] Whether the message should be spoken aloud
|
||||
* @property {MessageFlags} [flags] Which flags to set for the message.
|
||||
* <info>Only the {@link MessageFlags.SuppressEmbeds} flag can be set.</info>
|
||||
@@ -139,7 +139,7 @@ class Webhook {
|
||||
|
||||
/**
|
||||
* Options that can be passed into editMessage.
|
||||
* @typedef {BaseMessageOptions} WebhookEditMessageOptions
|
||||
* @typedef {BaseMessageOptions} WebhookMessageEditOptions
|
||||
* @property {Attachment[]} [attachments] Attachments to send with the message
|
||||
* @property {Snowflake} [threadId] The id of the thread this message belongs to
|
||||
* <info>For interaction webhooks, this property is ignored</info>
|
||||
@@ -156,7 +156,7 @@ class Webhook {
|
||||
|
||||
/**
|
||||
* Sends a message with this webhook.
|
||||
* @param {string|MessagePayload|WebhookCreateMessageOptions} options The options to provide
|
||||
* @param {string|MessagePayload|WebhookMessageCreateOptions} options The options to provide
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // Send a basic message
|
||||
@@ -261,7 +261,7 @@ class Webhook {
|
||||
|
||||
/**
|
||||
* Options used to edit a {@link Webhook}.
|
||||
* @typedef {Object} WebhookEditData
|
||||
* @typedef {Object} WebhookEditOptions
|
||||
* @property {string} [name=this.name] The new name for the webhook
|
||||
* @property {?(BufferResolvable)} [avatar] The new avatar for the webhook
|
||||
* @property {GuildTextChannelResolvable} [channel] The new channel for the webhook
|
||||
@@ -270,7 +270,7 @@ class Webhook {
|
||||
|
||||
/**
|
||||
* Edits this webhook.
|
||||
* @param {WebhookEditData} options Options for editing the webhook
|
||||
* @param {WebhookEditOptions} options Options for editing the webhook
|
||||
* @returns {Promise<Webhook>}
|
||||
*/
|
||||
async edit({ name = this.name, avatar, channel, reason }) {
|
||||
@@ -322,7 +322,7 @@ class Webhook {
|
||||
/**
|
||||
* Edits a message that was sent by this webhook.
|
||||
* @param {MessageResolvable|'@original'} message The message to edit
|
||||
* @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide
|
||||
* @param {string|MessagePayload|WebhookMessageEditOptions} options The options to provide
|
||||
* @returns {Promise<Message>} Returns the message edited by this webhook
|
||||
*/
|
||||
async editMessage(message, options) {
|
||||
|
||||
@@ -138,7 +138,7 @@ class InteractionResponses {
|
||||
|
||||
/**
|
||||
* Options that can be passed into {@link InteractionResponses#editReply}.
|
||||
* @typedef {WebhookEditMessageOptions} InteractionEditReplyOptions
|
||||
* @typedef {WebhookMessageEditOptions} InteractionEditReplyOptions
|
||||
* @property {MessageResolvable|'@original'} [message='@original'] The response to edit
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user