Skip to content

Commit a7b55c1

Browse files
MrMythicalYTSpaceEECkodiakhq[bot]
authored
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 <[email protected]> Co-authored-by: SpaceEEC <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 1b151db commit a7b55c1

27 files changed

+223
-221
lines changed

packages/discord.js/src/client/WebhookClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class WebhookClient extends BaseClient {
6868
/* eslint-disable no-empty-function, valid-jsdoc */
6969
/**
7070
* Sends a message with this webhook.
71-
* @param {string|MessagePayload|WebhookCreateMessageOptions} options The content for the reply
71+
* @param {string|MessagePayload|WebhookMessageCreateOptions} options The content for the reply
7272
* @returns {Promise<APIMessage>}
7373
*/
7474
send() {}
@@ -84,7 +84,7 @@ class WebhookClient extends BaseClient {
8484
/**
8585
* Edits a message that was sent by this webhook.
8686
* @param {MessageResolvable} message The message to edit
87-
* @param {string|MessagePayload|WebhookEditMessageOptions} options The options to provide
87+
* @param {string|MessagePayload|WebhookMessageEditOptions} options The options to provide
8888
* @returns {Promise<APIMessage>} Returns the message edited by this webhook
8989
*/
9090
editMessage() {}

packages/discord.js/src/managers/ApplicationCommandPermissionsManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ class ApplicationCommandPermissionsManager extends BaseManager {
112112
* Options used to set permissions for one or more Application Commands in a guild
113113
* <warn>Omitting the `command` parameter edits the guild wide permissions
114114
* when the manager's `commandId` is `null`</warn>
115-
* @typedef {BaseApplicationCommandPermissionsOptions} EditApplicationCommandPermissionsOptions
115+
* @typedef {BaseApplicationCommandPermissionsOptions} ApplicationCommandPermissionsEditOptions
116116
* @property {ApplicationCommandPermissions[]} permissions The new permissions for the guild or overwrite
117117
* @property {string} token The bearer token to use that authorizes the permission edit
118118
*/
119119

120120
/**
121121
* Sets the permissions for the guild or a command overwrite.
122-
* @param {EditApplicationCommandPermissionsOptions} options Options used to set permissions
122+
* @param {ApplicationCommandPermissionsEditOptions} options Options used to set permissions
123123
* @returns {Promise<ApplicationCommandPermissions[]|Collection<Snowflake, ApplicationCommandPermissions[]>>}
124124
* @example
125125
* // Set a permission overwrite for a command
@@ -179,7 +179,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
179179

180180
/**
181181
* Add permissions to a command.
182-
* @param {EditApplicationCommandPermissionsOptions} options Options used to add permissions
182+
* @param {ApplicationCommandPermissionsEditOptions} options Options used to add permissions
183183
* @returns {Promise<ApplicationCommandPermissions[]>}
184184
* @example
185185
* // Add a rule to block a role from using a command

packages/discord.js/src/managers/GuildChannelManager.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,27 @@ class GuildChannelManager extends CachedManager {
258258
/**
259259
* Edits the channel.
260260
* @param {GuildChannelResolvable} channel The channel to edit
261-
* @param {GuildChannelEditOptions} data Options for editing the channel
261+
* @param {GuildChannelEditOptions} options Options for editing the channel
262262
* @returns {Promise<GuildChannel>}
263263
* @example
264264
* // Edit a channel
265265
* guild.channels.edit('222197033908436994', { name: 'new-channel' })
266266
* .then(console.log)
267267
* .catch(console.error);
268268
*/
269-
async edit(channel, data) {
269+
async edit(channel, options) {
270270
channel = this.resolve(channel);
271271
if (!channel) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'GuildChannelResolvable');
272272

273-
const parent = data.parent && this.client.channels.resolveId(data.parent);
273+
const parent = options.parent && this.client.channels.resolveId(options.parent);
274274

275-
if (typeof data.position !== 'undefined') {
276-
await this.setPosition(channel, data.position, { position: data.position, reason: data.reason });
275+
if (typeof options.position !== 'undefined') {
276+
await this.setPosition(channel, options.position, { position: options.position, reason: options.reason });
277277
}
278278

279-
let permission_overwrites = data.permissionOverwrites?.map(o => PermissionOverwrites.resolve(o, this.guild));
279+
let permission_overwrites = options.permissionOverwrites?.map(o => PermissionOverwrites.resolve(o, this.guild));
280280

281-
if (data.lockPermissions) {
281+
if (options.lockPermissions) {
282282
if (parent) {
283283
const newParent = this.guild.channels.resolve(parent);
284284
if (newParent?.type === ChannelType.GuildCategory) {
@@ -295,26 +295,27 @@ class GuildChannelManager extends CachedManager {
295295

296296
const newData = await this.client.rest.patch(Routes.channel(channel.id), {
297297
body: {
298-
name: (data.name ?? channel.name).trim(),
299-
type: data.type,
300-
topic: data.topic,
301-
nsfw: data.nsfw,
302-
bitrate: data.bitrate ?? channel.bitrate,
303-
user_limit: data.userLimit ?? channel.userLimit,
304-
rtc_region: 'rtcRegion' in data ? data.rtcRegion : channel.rtcRegion,
305-
video_quality_mode: data.videoQualityMode,
298+
name: (options.name ?? channel.name).trim(),
299+
type: options.type,
300+
topic: options.topic,
301+
nsfw: options.nsfw,
302+
bitrate: options.bitrate ?? channel.bitrate,
303+
user_limit: options.userLimit ?? channel.userLimit,
304+
rtc_region: 'rtcRegion' in options ? options.rtcRegion : channel.rtcRegion,
305+
video_quality_mode: options.videoQualityMode,
306306
parent_id: parent,
307-
lock_permissions: data.lockPermissions,
308-
rate_limit_per_user: data.rateLimitPerUser,
309-
default_auto_archive_duration: data.defaultAutoArchiveDuration,
307+
lock_permissions: options.lockPermissions,
308+
rate_limit_per_user: options.rateLimitPerUser,
309+
default_auto_archive_duration: options.defaultAutoArchiveDuration,
310310
permission_overwrites,
311-
available_tags: data.availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
312-
default_reaction_emoji: data.defaultReactionEmoji && transformGuildDefaultReaction(data.defaultReactionEmoji),
313-
default_thread_rate_limit_per_user: data.defaultThreadRateLimitPerUser,
314-
flags: 'flags' in data ? ChannelFlagsBitField.resolve(data.flags) : undefined,
315-
default_sort_order: data.defaultSortOrder,
311+
available_tags: options.availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
312+
default_reaction_emoji:
313+
options.defaultReactionEmoji && transformGuildDefaultReaction(options.defaultReactionEmoji),
314+
default_thread_rate_limit_per_user: options.defaultThreadRateLimitPerUser,
315+
flags: 'flags' in options ? ChannelFlagsBitField.resolve(options.flags) : undefined,
316+
default_sort_order: options.defaultSortOrder,
316317
},
317-
reason: data.reason,
318+
reason: options.reason,
318319
});
319320

320321
return this.client.actions.ChannelUpdate.handle(newData).updated;

packages/discord.js/src/managers/GuildEmojiManager.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
124124
/**
125125
* Edits an emoji.
126126
* @param {EmojiResolvable} emoji The Emoji resolvable to edit
127-
* @param {GuildEmojiEditData} data The new data for the emoji
127+
* @param {GuildEmojiEditOptions} options The options to provide
128128
* @returns {Promise<GuildEmoji>}
129129
*/
130-
async edit(emoji, data) {
130+
async edit(emoji, options) {
131131
const id = this.resolveId(emoji);
132132
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
133-
const roles = data.roles?.map(r => this.guild.roles.resolveId(r));
133+
const roles = options.roles?.map(r => this.guild.roles.resolveId(r));
134134
const newData = await this.client.rest.patch(Routes.guildEmoji(this.guild.id, id), {
135135
body: {
136-
name: data.name,
136+
name: options.name,
137137
roles,
138138
},
139-
reason: data.reason,
139+
reason: options.reason,
140140
});
141141
const existing = this.cache.get(id);
142142
if (existing) {

packages/discord.js/src/managers/GuildInviteManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class GuildInviteManager extends CachedManager {
167167
/**
168168
* Create an invite to the guild from the provided channel.
169169
* @param {GuildInvitableChannelResolvable} channel The options for creating the invite from a channel.
170-
* @param {CreateInviteOptions} [options={}] The options for creating the invite from a channel.
170+
* @param {InviteCreateOptions} [options={}] The options for creating the invite from a channel.
171171
* @returns {Promise<Invite>}
172172
* @example
173173
* // Create an invite to a selected channel

packages/discord.js/src/managers/GuildMemberManager.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class GuildMemberManager extends CachedManager {
270270

271271
/**
272272
* The data for editing a guild member.
273-
* @typedef {Object} GuildMemberEditData
273+
* @typedef {Object} GuildMemberEditOptions
274274
* @property {?string} [nick] The nickname to set for the member
275275
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles or role ids to apply
276276
* @property {boolean} [mute] Whether or not the member should be muted
@@ -286,43 +286,43 @@ class GuildMemberManager extends CachedManager {
286286
* Edits a member of the guild.
287287
* <info>The user must be a member of the guild</info>
288288
* @param {UserResolvable} user The member to edit
289-
* @param {GuildMemberEditData} data The data to edit the member with
289+
* @param {GuildMemberEditOptions} options The options to provide
290290
* @returns {Promise<GuildMember>}
291291
*/
292-
async edit(user, { reason, ...data }) {
292+
async edit(user, { reason, ...options }) {
293293
const id = this.client.users.resolveId(user);
294294
if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable');
295295

296-
if (data.channel) {
297-
data.channel = this.guild.channels.resolve(data.channel);
298-
if (!(data.channel instanceof BaseGuildVoiceChannel)) {
296+
if (options.channel) {
297+
options.channel = this.guild.channels.resolve(options.channel);
298+
if (!(options.channel instanceof BaseGuildVoiceChannel)) {
299299
throw new DiscordjsError(ErrorCodes.GuildVoiceChannelResolve);
300300
}
301-
data.channel_id = data.channel.id;
302-
data.channel = undefined;
303-
} else if (data.channel === null) {
304-
data.channel_id = null;
305-
data.channel = undefined;
301+
options.channel_id = options.channel.id;
302+
options.channel = undefined;
303+
} else if (options.channel === null) {
304+
options.channel_id = null;
305+
options.channel = undefined;
306306
}
307-
data.roles &&= data.roles.map(role => (role instanceof Role ? role.id : role));
307+
options.roles &&= options.roles.map(role => (role instanceof Role ? role.id : role));
308308

309-
if (typeof data.communicationDisabledUntil !== 'undefined') {
310-
data.communication_disabled_until =
309+
if (typeof options.communicationDisabledUntil !== 'undefined') {
310+
options.communication_disabled_until =
311311
// eslint-disable-next-line eqeqeq
312-
data.communicationDisabledUntil != null
313-
? new Date(data.communicationDisabledUntil).toISOString()
314-
: data.communicationDisabledUntil;
312+
options.communicationDisabledUntil != null
313+
? new Date(options.communicationDisabledUntil).toISOString()
314+
: options.communicationDisabledUntil;
315315
}
316316

317317
let endpoint;
318318
if (id === this.client.user.id) {
319-
const keys = Object.keys(data);
319+
const keys = Object.keys(options);
320320
if (keys.length === 1 && keys[0] === 'nick') endpoint = Routes.guildMember(this.guild.id);
321321
else endpoint = Routes.guildMember(this.guild.id, id);
322322
} else {
323323
endpoint = Routes.guildMember(this.guild.id, id);
324324
}
325-
const d = await this.client.rest.patch(endpoint, { body: data, reason });
325+
const d = await this.client.rest.patch(endpoint, { body: options, reason });
326326

327327
const clone = this.cache.get(id)?._clone();
328328
clone?._patch(d);

packages/discord.js/src/managers/GuildStickerManager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ class GuildStickerManager extends CachedManager {
101101
/**
102102
* Edits a sticker.
103103
* @param {StickerResolvable} sticker The sticker to edit
104-
* @param {GuildStickerEditData} [data={}] The new data for the sticker
104+
* @param {GuildStickerEditOptions} [options={}] The new data for the sticker
105105
* @returns {Promise<Sticker>}
106106
*/
107-
async edit(sticker, data = {}) {
107+
async edit(sticker, options = {}) {
108108
const stickerId = this.resolveId(sticker);
109109
if (!stickerId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'sticker', 'StickerResolvable');
110110

111111
const d = await this.client.rest.patch(Routes.guildSticker(this.guild.id, stickerId), {
112-
body: data,
113-
reason: data.reason,
112+
body: options,
113+
reason: options.reason,
114114
});
115115

116116
const existing = this.cache.get(stickerId);

packages/discord.js/src/managers/RoleManager.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class RoleManager extends CachedManager {
100100

101101
/**
102102
* Options used to create a new role.
103-
* @typedef {Object} CreateRoleOptions
103+
* @typedef {Object} RoleCreateOptions
104104
* @property {string} [name] The name of the new role
105105
* @property {ColorResolvable} [color] The data to create the role with
106106
* @property {boolean} [hoist] Whether or not the new role should be hoisted
@@ -117,7 +117,7 @@ class RoleManager extends CachedManager {
117117
/**
118118
* Creates a new role in the guild with given information.
119119
* <warn>The position will silently reset to 1 if an invalid one is provided, or none.</warn>
120-
* @param {CreateRoleOptions} [options] Options for creating the new role
120+
* @param {RoleCreateOptions} [options] Options for creating the new role
121121
* @returns {Promise<Role>}
122122
* @example
123123
* // Create a new role
@@ -166,47 +166,48 @@ class RoleManager extends CachedManager {
166166

167167
/**
168168
* Options for editing a role
169-
* @typedef {RoleData} EditRoleOptions
169+
* @typedef {RoleData} RoleEditOptions
170170
* @property {string} [reason] The reason for editing this role
171171
*/
172172

173173
/**
174174
* Edits a role of the guild.
175175
* @param {RoleResolvable} role The role to edit
176-
* @param {EditRoleOptions} data The new data for the role
176+
* @param {RoleEditOptions} options The options to provide
177177
* @returns {Promise<Role>}
178178
* @example
179179
* // Edit a role
180180
* guild.roles.edit('222079219327434752', { name: 'buddies' })
181181
* .then(updated => console.log(`Edited role name to ${updated.name}`))
182182
* .catch(console.error);
183183
*/
184-
async edit(role, data) {
184+
async edit(role, options) {
185185
role = this.resolve(role);
186186
if (!role) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'role', 'RoleResolvable');
187187

188-
if (typeof data.position === 'number') {
189-
await this.setPosition(role, data.position, { reason: data.reason });
188+
if (typeof options.position === 'number') {
189+
await this.setPosition(role, options.position, { reason: options.reason });
190190
}
191191

192-
let icon = data.icon;
192+
let icon = options.icon;
193193
if (icon) {
194194
const guildEmojiURL = this.guild.emojis.resolve(icon)?.url;
195195
icon = guildEmojiURL ? await DataResolver.resolveImage(guildEmojiURL) : await DataResolver.resolveImage(icon);
196196
if (typeof icon !== 'string') icon = undefined;
197197
}
198198

199199
const body = {
200-
name: data.name,
201-
color: typeof data.color === 'undefined' ? undefined : resolveColor(data.color),
202-
hoist: data.hoist,
203-
permissions: typeof data.permissions === 'undefined' ? undefined : new PermissionsBitField(data.permissions),
204-
mentionable: data.mentionable,
200+
name: options.name,
201+
color: typeof options.color === 'undefined' ? undefined : resolveColor(options.color),
202+
hoist: options.hoist,
203+
permissions:
204+
typeof options.permissions === 'undefined' ? undefined : new PermissionsBitField(options.permissions),
205+
mentionable: options.mentionable,
205206
icon,
206-
unicode_emoji: data.unicodeEmoji,
207+
unicode_emoji: options.unicodeEmoji,
207208
};
208209

209-
const d = await this.client.rest.patch(Routes.guildRole(this.guild.id, role.id), { body, reason: data.reason });
210+
const d = await this.client.rest.patch(Routes.guildRole(this.guild.id, role.id), { body, reason: options.reason });
210211

211212
const clone = role._clone();
212213
clone._patch(d);

packages/discord.js/src/structures/BaseGuildTextChannel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class BaseGuildTextChannel extends GuildChannel {
125125

126126
/**
127127
* Options used to create an invite to a guild channel.
128-
* @typedef {Object} CreateInviteOptions
128+
* @typedef {Object} InviteCreateOptions
129129
* @property {boolean} [temporary] Whether members that joined via the invite should be automatically
130130
* kicked after 24 hours if they have not yet received a role
131131
* @property {number} [maxAge] How long the invite should last (in seconds, 0 for forever)
@@ -142,7 +142,7 @@ class BaseGuildTextChannel extends GuildChannel {
142142

143143
/**
144144
* Creates an invite to this guild channel.
145-
* @param {CreateInviteOptions} [options={}] The options for creating the invite
145+
* @param {InviteCreateOptions} [options={}] The options for creating the invite
146146
* @returns {Promise<Invite>}
147147
* @example
148148
* // Create an invite to a channel

packages/discord.js/src/structures/BaseGuildVoiceChannel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class BaseGuildVoiceChannel extends GuildChannel {
9898

9999
/**
100100
* Creates an invite to this guild channel.
101-
* @param {CreateInviteOptions} [options={}] The options for creating the invite
101+
* @param {InviteCreateOptions} [options={}] The options for creating the invite
102102
* @returns {Promise<Invite>}
103103
* @example
104104
* // Create an invite to a channel

packages/discord.js/src/structures/ClientUser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ class ClientUser extends User {
4444

4545
/**
4646
* Data used to edit the logged in client
47-
* @typedef {Object} ClientUserEditData
47+
* @typedef {Object} ClientUserEditOptions
4848
* @property {string} [username] The new username
4949
* @property {?(BufferResolvable|Base64Resolvable)} [avatar] The new avatar
5050
*/
5151

5252
/**
5353
* Edits the logged in client.
54-
* @param {ClientUserEditData} data The new data
54+
* @param {ClientUserEditOptions} options The options to provide
5555
* @returns {Promise<ClientUser>}
5656
*/
57-
async edit(data) {
58-
if (typeof data.avatar !== 'undefined') data.avatar = await DataResolver.resolveImage(data.avatar);
59-
const newData = await this.client.rest.patch(Routes.user(), { body: data });
57+
async edit(options) {
58+
if (typeof options.avatar !== 'undefined') options.avatar = await DataResolver.resolveImage(options.avatar);
59+
const newData = await this.client.rest.patch(Routes.user(), { body: options });
6060
this.client.token = newData.token;
6161
this.client.rest.setToken(newData.token);
6262
const { updated } = this.client.actions.UserUpdate.handle(newData);

packages/discord.js/src/structures/ForumChannel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class ForumChannel extends GuildChannel {
168168

169169
/**
170170
* Creates an invite to this guild channel.
171-
* @param {CreateInviteOptions} [options={}] The options for creating the invite
171+
* @param {InviteCreateOptions} [options={}] The options for creating the invite
172172
* @returns {Promise<Invite>}
173173
* @example
174174
* // Create an invite to a channel

0 commit comments

Comments
 (0)