refactor: change xID to xId (#6036)

* refactor: change `xID` to `xId`

* Update src/managers/MessageManager.js

Co-authored-by: Noel <buechler.noel@outlook.com>

Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
Antonio Román
2021-07-04 20:54:27 +02:00
committed by GitHub
parent 281072be44
commit a7c6678c72
95 changed files with 963 additions and 963 deletions

View File

@@ -27,21 +27,21 @@ class ApplicationCommandManager extends CachedManager {
* @name ApplicationCommandManager#cache
*/
add(data, cache, guildID) {
return super.add(data, cache, { extras: [this.guild, guildID] });
add(data, cache, guildId) {
return super.add(data, cache, { extras: [this.guild, guildId] });
}
/**
* The APIRouter path to the commands
* @param {Snowflake} [options.id] ID of the application command
* @param {Snowflake} [options.guildID] ID of the guild to use in the path,
* @param {Snowflake} [options.id] The application command's id
* @param {Snowflake} [options.guildId] The guild's id to use in the path,
* ignored when using a {@link GuildApplicationCommandManager}
* @returns {Object}
* @private
*/
commandPath({ id, guildID } = {}) {
commandPath({ id, guildId } = {}) {
let path = this.client.api.applications(this.client.application.id);
if (this.guild ?? guildID) path = path.guilds(this.guild?.id ?? guildID);
if (this.guild ?? guildId) path = path.guilds(this.guild?.id ?? guildId);
return id ? path.commands(id) : path.commands;
}
@@ -62,12 +62,12 @@ class ApplicationCommandManager extends CachedManager {
/**
* Options used to fetch Application Commands from discord
* @typedef {BaseFetchOptions} FetchApplicationCommandOptions
* @property {Snowflake} [guildID] ID of the guild to fetch commands for, for when the guild is not cached
* @property {Snowflake} [guildId] The guild's id to fetch commands for, for when the guild is not cached
*/
/**
* Obtains one or multiple application commands from Discord, or the cache if it's already available.
* @param {Snowflake} [id] ID of the application command
* @param {Snowflake} [id] The application command's id
* @param {FetchApplicationCommandOptions} [options] Additional options for this fetch
* @returns {Promise<ApplicationCommand|Collection<Snowflake, ApplicationCommand>>}
* @example
@@ -81,26 +81,26 @@ class ApplicationCommandManager extends CachedManager {
* .then(commands => console.log(`Fetched ${commands.size} commands`))
* .catch(console.error);
*/
async fetch(id, { guildID, cache = true, force = false } = {}) {
async fetch(id, { guildId, cache = true, force = false } = {}) {
if (typeof id === 'object') {
({ guildID, cache = true, force = false } = id);
({ guildId, cache = true, force = false } = id);
} else if (id) {
if (!force) {
const existing = this.cache.get(id);
if (existing) return existing;
}
const command = await this.commandPath({ id, guildID }).get();
const command = await this.commandPath({ id, guildId }).get();
return this.add(command, cache);
}
const data = await this.commandPath({ guildID }).get();
return data.reduce((coll, command) => coll.set(command.id, this.add(command, cache, guildID)), new Collection());
const data = await this.commandPath({ guildId }).get();
return data.reduce((coll, command) => coll.set(command.id, this.add(command, cache, guildId)), new Collection());
}
/**
* Creates an application command.
* @param {ApplicationCommandData} command The command
* @param {Snowflake} [guildID] ID of the guild to create this command in,
* @param {Snowflake} [guildId] The guild's id to create this command in,
* ignored when using a {@link GuildApplicationCommandManager}
* @returns {Promise<ApplicationCommand>}
* @example
@@ -112,17 +112,17 @@ class ApplicationCommandManager extends CachedManager {
* .then(console.log)
* .catch(console.error);
*/
async create(command, guildID) {
const data = await this.commandPath({ guildID }).post({
async create(command, guildId) {
const data = await this.commandPath({ guildId }).post({
data: this.constructor.transformCommand(command),
});
return this.add(data, undefined, guildID);
return this.add(data, undefined, guildId);
}
/**
* Sets all the commands for this application or guild.
* @param {ApplicationCommandData[]} commands The commands
* @param {Snowflake} [guildID] ID of the guild to create the commands in,
* @param {Snowflake} [guildId] The guild's id to create the commands in,
* ignored when using a {@link GuildApplicationCommandManager}
* @returns {Promise<Collection<Snowflake, ApplicationCommand>>}
* @example
@@ -141,12 +141,12 @@ class ApplicationCommandManager extends CachedManager {
* .then(console.log)
* .catch(console.error);
*/
async set(commands, guildID) {
const data = await this.commandPath({ guildID }).put({
async set(commands, guildId) {
const data = await this.commandPath({ guildId }).put({
data: commands.map(c => this.constructor.transformCommand(c)),
});
return data.reduce(
(coll, command) => coll.set(command.id, this.add(command, undefined, guildID)),
(coll, command) => coll.set(command.id, this.add(command, undefined, guildId)),
new Collection(),
);
}
@@ -155,7 +155,7 @@ class ApplicationCommandManager extends CachedManager {
* Edits an application command.
* @param {ApplicationCommandResolvable} command The command to edit
* @param {ApplicationCommandData} data The data to update the command with
* @param {Snowflake} [guildID] ID of the guild where the command registered,
* @param {Snowflake} [guildId] The guild's id where the command registered,
* ignored when using a {@link GuildApplicationCommandManager}
* @returns {Promise<ApplicationCommand>}
* @example
@@ -166,18 +166,18 @@ class ApplicationCommandManager extends CachedManager {
* .then(console.log)
* .catch(console.error);
*/
async edit(command, data, guildID) {
const id = this.resolveID(command);
async edit(command, data, guildId) {
const id = this.resolveId(command);
if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
const patched = await this.commandPath({ id, guildID }).patch({ data: this.constructor.transformCommand(data) });
return this.add(patched, undefined, guildID);
const patched = await this.commandPath({ id, guildId }).patch({ data: this.constructor.transformCommand(data) });
return this.add(patched, undefined, guildId);
}
/**
* Deletes an application command.
* @param {ApplicationCommandResolvable} command The command to delete
* @param {Snowflake} [guildID] ID of the guild where the command is registered,
* @param {Snowflake} [guildId] The guild's id where the command is registered,
* ignored when using a {@link GuildApplicationCommandManager}
* @returns {Promise<?ApplicationCommand>}
* @example
@@ -186,11 +186,11 @@ class ApplicationCommandManager extends CachedManager {
* .then(console.log)
* .catch(console.error);
*/
async delete(command, guildID) {
const id = this.resolveID(command);
async delete(command, guildId) {
const id = this.resolveId(command);
if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
await this.commandPath({ id, guildID }).delete();
await this.commandPath({ id, guildId }).delete();
const cached = this.cache.get(id);
this.cache.delete(id);

View File

@@ -29,30 +29,30 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* The id of the guild that this manager acts on
* @type {?Snowflake}
*/
this.guildID = manager.guildID ?? manager.guild?.id ?? null;
this.guildId = manager.guildId ?? manager.guild?.id ?? null;
/**
* The id of the command this manager acts on
* @type {?Snowflake}
*/
this.commandID = manager.id ?? null;
this.commandId = manager.id ?? null;
}
/**
* The APIRouter path to the commands
* @param {Snowflake} guildID ID of the guild to use in the path,
* @param {Snowflake} [commandID] ID of the application command
* @param {Snowflake} guildId The guild's id to use in the path,
* @param {Snowflake} [commandId] The application command's id
* @returns {Object}
* @private
*/
permissionsPath(guildID, commandID) {
return this.client.api.applications(this.client.application.id).guilds(guildID).commands(commandID).permissions;
permissionsPath(guildId, commandId) {
return this.client.api.applications(this.client.application.id).guilds(guildId).commands(commandId).permissions;
}
/**
* Data for setting the permissions of an application command.
* @typedef {Object} ApplicationCommandPermissionData
* @property {Snowflake} id The ID of the role or user
* @property {Snowflake} id The role or user's id
* @property {ApplicationCommandPermissionType|number} type Whether this permission is for a role or a user
* @property {boolean} permission Whether the role or user has the permission to use this command
*/
@@ -60,20 +60,20 @@ class ApplicationCommandPermissionsManager extends BaseManager {
/**
* The object returned when fetching permissions for an application command.
* @typedef {Object} ApplicationCommandPermissions
* @property {Snowflake} id The ID of the role or user
* @property {Snowflake} id The role or user's id
* @property {ApplicationCommandPermissionType} type Whether this permission is for a role or a user
* @property {boolean} permission Whether the role or user has the permission to use this command
*/
/**
* Options for managing permissions for one or more Application Commands
* <warn>When passing these options to a manager where `guildID` is `null`,
* <warn>When passing these options to a manager where `guildId` is `null`,
* `guild` is a required parameter</warn>
* @typedef {Object} BaseApplicationCommandPermissionsOptions
* @param {GuildResolvable} [guild] The guild to modify / check permissions for
* <warn>Ignored when the manager has a non-null `guildID` property</warn>
* <warn>Ignored when the manager has a non-null `guildId` property</warn>
* @param {ApplicationCommandResolvable} [command] The command to modify / check permissions for
* <warn>Ignored when the manager has a non-null `commandID` property</warn>
* <warn>Ignored when the manager has a non-null `commandId` property</warn>
*/
/**
@@ -92,13 +92,13 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async fetch({ guild, command } = {}) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (commandID) {
const data = await this.permissionsPath(guildID, commandID).get();
const { guildId, commandId } = this._validateOptions(guild, command);
if (commandId) {
const data = await this.permissionsPath(guildId, commandId).get();
return data.permissions.map(perm => this.constructor.transformPermissions(perm, true));
}
const data = await this.permissionsPath(guildID).get();
const data = await this.permissionsPath(guildId).get();
return data.reduce(
(coll, perm) =>
coll.set(
@@ -112,14 +112,14 @@ class ApplicationCommandPermissionsManager extends BaseManager {
/**
* Data used for overwriting the permissions for all application commands in a guild.
* @typedef {Object} GuildApplicationCommandPermissionData
* @property {Snowflake} id The ID of the command
* @property {Snowflake} id The command's id
* @property {ApplicationCommandPermissionData[]} permissions The permissions for this command
*/
/**
* Options used to set permissions for one or more Application Commands in a guild
* <warn>One of `command` AND `permissions`, OR `fullPermissions` is required.
* `fullPermissions` is not a valid option when passing to a manager where `commandID` is non-null</warn>
* `fullPermissions` is not a valid option when passing to a manager where `commandId` is non-null</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} SetApplicationCommandPermissionsOptions
* @param {ApplicationCommandPermissionData[]} [permissions] The new permissions for the command
* @param {GuildApplicationCommandPermissionData[]} [fullPermissions] The new permissions for all commands
@@ -157,13 +157,13 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async set({ guild, command, permissions, fullPermissions } = {}) {
const { guildID, commandID } = this._validateOptions(guild, command);
const { guildId, commandId } = this._validateOptions(guild, command);
if (commandID) {
if (commandId) {
if (!Array.isArray(permissions)) {
throw new TypeError('INVALID_TYPE', 'permissions', 'Array of ApplicationCommandPermissionData', true);
}
const data = await this.permissionsPath(guildID, commandID).put({
const data = await this.permissionsPath(guildId, commandId).put({
data: { permissions: permissions.map(perm => this.constructor.transformPermissions(perm)) },
});
return data.permissions.map(perm => this.constructor.transformPermissions(perm, true));
@@ -181,7 +181,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
permissions: perm.permissions.map(p => this.constructor.transformPermissions(p)),
});
}
const data = await this.permissionsPath(guildID).put({
const data = await this.permissionsPath(guildId).put({
data: APIPermissions,
});
return data.reduce(
@@ -196,7 +196,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
/**
* Options used to add permissions to a command
* <warn>The `command` parameter is not optional when the managers `commandID` is `null`</warn>
* <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} AddApplicationCommandPermissionsOptions
* @param {ApplicationCommandPermissionData[]} permissions The permissions to add to the command
*/
@@ -218,15 +218,15 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async add({ guild, command, permissions }) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (!commandID) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
const { guildId, commandId } = this._validateOptions(guild, command);
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
if (!Array.isArray(permissions)) {
throw new TypeError('INVALID_TYPE', 'permissions', 'Array of ApplicationCommandPermissionData', true);
}
let existing = [];
try {
existing = await this.fetch({ guild: guildID, command: commandID });
existing = await this.fetch({ guild: guildId, command: commandId });
} catch (error) {
if (error.code !== APIErrors.UNKNOWN_APPLICATION_COMMAND_PERMISSIONS) throw error;
}
@@ -238,12 +238,12 @@ class ApplicationCommandPermissionsManager extends BaseManager {
}
}
return this.set({ guild: guildID, command: commandID, permissions: newPermissions });
return this.set({ guild: guildId, command: commandId, permissions: newPermissions });
}
/**
* Options used to remove permissions from a command
* <warn>The `command` parameter is not optional when the managers `commandID` is `null`</warn>
* <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} RemoveApplicationCommandPermissionsOptions
* @param {UserResolvable|UserResolvable[]} [users] The user(s) to remove from the command permissions
* <warn>One of `users` or `roles` is required</warn>
@@ -269,67 +269,67 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async remove({ guild, command, users, roles }) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (!commandID) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
const { guildId, commandId } = this._validateOptions(guild, command);
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
if (!users && !roles) throw new TypeError('INVALID_TYPE', 'users OR roles', 'Array or Resolvable', true);
let resolvedIDs = [];
let resolvedIds = [];
if (Array.isArray(users)) {
users.forEach(user => {
const userID = this.client.users.resolveID(user);
if (!userID) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', user);
resolvedIDs.push(userID);
const userId = this.client.users.resolveId(user);
if (!userId) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', user);
resolvedIds.push(userId);
});
} else if (users) {
const userID = this.client.users.resolveID(users);
if (!userID) {
const userId = this.client.users.resolveId(users);
if (!userId) {
throw new TypeError('INVALID_TYPE', 'users', 'Array or UserResolvable');
}
resolvedIDs.push(userID);
resolvedIds.push(userId);
}
if (Array.isArray(roles)) {
roles.forEach(role => {
if (typeof role === 'string') {
resolvedIDs.push(role);
resolvedIds.push(role);
return;
}
if (!this.guild) throw new Error('GUILD_UNCACHED_ROLE_RESOLVE');
const roleID = this.guild.roles.resolveID(role);
if (!roleID) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', role);
resolvedIDs.push(roleID);
const roleId = this.guild.roles.resolveId(role);
if (!roleId) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', role);
resolvedIds.push(roleId);
});
} else if (roles) {
if (typeof roles === 'string') {
resolvedIDs.push(roles);
resolvedIds.push(roles);
} else {
if (!this.guild) throw new Error('GUILD_UNCACHED_ROLE_RESOLVE');
const roleID = this.guild.roles.resolveID(roles);
if (!roleID) {
const roleId = this.guild.roles.resolveId(roles);
if (!roleId) {
throw new TypeError('INVALID_TYPE', 'users', 'Array or RoleResolvable');
}
resolvedIDs.push(roleID);
resolvedIds.push(roleId);
}
}
let existing = [];
try {
existing = await this.fetch({ guild: guildID, command: commandID });
existing = await this.fetch({ guild: guildId, command: commandId });
} catch (error) {
if (error.code !== APIErrors.UNKNOWN_APPLICATION_COMMAND_PERMISSIONS) throw error;
}
const permissions = existing.filter(perm => !resolvedIDs.includes(perm.id));
const permissions = existing.filter(perm => !resolvedIds.includes(perm.id));
return this.set({ guild: guildID, command: commandID, permissions });
return this.set({ guild: guildId, command: commandId, permissions });
}
/**
* Options used to check existance of permissions on a command
* <warn>The `command` parameter is not optional when the managers `commandID` is `null`</warn>
* <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} HasApplicationCommandPermissionsOptions
* @param {UserResolvable|RoleResolvable} permissionID The user or role to check if a permission exists for
* @param {UserResolvable|RoleResolvable} permissionId The user or role to check if a permission exists for
* on this command.
*/
@@ -339,54 +339,54 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* @returns {Promise<boolean>}
* @example
* // Check whether a user has permission to use a command
* guild.commands.permissions.has({ command: '123456789012345678', permissionID: '876543210123456789' })
* guild.commands.permissions.has({ command: '123456789012345678', permissionId: '876543210123456789' })
* .then(console.log)
* .catch(console.error);
*/
async has({ guild, command, permissionID }) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (!commandID) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
async has({ guild, command, permissionId }) {
const { guildId, commandId } = this._validateOptions(guild, command);
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
if (!permissionID) throw new TypeError('INVALID_TYPE', 'permissionsID', 'UserResolvable or RoleResolvable');
let resolvedID = permissionID;
if (typeof permissionID !== 'string') {
resolvedID = this.client.users.resolveID(permissionID);
if (!resolvedID) {
if (!permissionId) throw new TypeError('INVALID_TYPE', 'permissionsId', 'UserResolvable or RoleResolvable');
let resolvedId = permissionId;
if (typeof permissionId !== 'string') {
resolvedId = this.client.users.resolveId(permissionId);
if (!resolvedId) {
if (!this.guild) throw new Error('GUILD_UNCACHED_ROLE_RESOLVE');
resolvedID = this.guild.roles.resolveID(permissionID);
resolvedId = this.guild.roles.resolveId(permissionId);
}
if (!resolvedID) {
throw new TypeError('INVALID_TYPE', 'permissionID', 'UserResolvable or RoleResolvable');
if (!resolvedId) {
throw new TypeError('INVALID_TYPE', 'permissionId', 'UserResolvable or RoleResolvable');
}
}
let existing = [];
try {
existing = await this.fetch({ guild: guildID, command: commandID });
existing = await this.fetch({ guild: guildId, command: commandId });
} catch (error) {
if (error.code !== APIErrors.UNKNOWN_APPLICATION_COMMAND_PERMISSIONS) throw error;
}
return existing.some(perm => perm.id === resolvedID);
return existing.some(perm => perm.id === resolvedId);
}
_validateOptions(guild, command) {
const guildID = this.guildID ?? this.client.guilds.resolveID(guild);
if (!guildID) throw new Error('GLOBAL_COMMAND_PERMISSIONS');
let commandID = this.commandID;
if (command && !commandID) {
commandID = this.manager.resolveID?.(command);
if (!commandID && this.guild) {
commandID = this.guild.commands.resolveID(command);
const guildId = this.guildId ?? this.client.guilds.resolveId(guild);
if (!guildId) throw new Error('GLOBAL_COMMAND_PERMISSIONS');
let commandId = this.commandId;
if (command && !commandId) {
commandId = this.manager.resolveId?.(command);
if (!commandId && this.guild) {
commandId = this.guild.commands.resolveId(command);
}
if (!commandID) {
commandID = this.client.application?.commands.resolveID(command);
if (!commandId) {
commandId = this.client.application?.commands.resolveId(command);
}
if (!commandID) {
if (!commandId) {
throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable', true);
}
}
return { guildID, commandID };
return { guildId, commandId };
}
/**

View File

@@ -22,7 +22,7 @@ class BaseGuildEmojiManager extends CachedManager {
/**
* Data that can be resolved into a GuildEmoji object. This can be:
* * A custom emoji ID
* * A custom emoji identifier
* * A GuildEmoji object
* * A ReactionEmoji object
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable
@@ -39,13 +39,13 @@ class BaseGuildEmojiManager extends CachedManager {
}
/**
* Resolves an EmojiResolvable to an Emoji ID string.
* Resolves an EmojiResolvable to an Emoji id string.
* @param {EmojiResolvable} emoji The Emoji resolvable to identify
* @returns {?Snowflake}
*/
resolveID(emoji) {
resolveId(emoji) {
if (emoji instanceof ReactionEmoji) return emoji.id;
return super.resolveID(emoji);
return super.resolveId(emoji);
}
/**

View File

@@ -66,8 +66,8 @@ class ChannelManager extends CachedManager {
*/
/**
* Resolves a ChannelResolvable to a channel ID string.
* @method resolveID
* Resolves a ChannelResolvable to a channel id string.
* @method resolveId
* @memberof ChannelManager
* @instance
* @param {ChannelResolvable} channel The channel resolvable to resolve
@@ -76,7 +76,7 @@ class ChannelManager extends CachedManager {
/**
* Obtains a channel from Discord, or the channel cache if it's already available.
* @param {Snowflake} id ID of the channel
* @param {Snowflake} id The channel's id
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<?Channel>}
* @example

View File

@@ -43,11 +43,11 @@ class DataManager extends BaseManager {
}
/**
* Resolves a data entry to an instance ID.
* Resolves a data entry to an instance id.
* @param {string|Object} idOrInstance The id or instance of something in this Manager
* @returns {?Snowflake}
*/
resolveID(idOrInstance) {
resolveId(idOrInstance) {
if (idOrInstance instanceof this.holds) return idOrInstance.id;
if (typeof idOrInstance === 'string') return idOrInstance;
return null;

View File

@@ -44,7 +44,7 @@ class GuildBanManager extends CachedManager {
* @returns {?GuildBan}
*/
resolve(ban) {
return super.resolve(ban) ?? super.resolve(this.client.users.resolveID(ban));
return super.resolve(ban) ?? super.resolve(this.client.users.resolveId(ban));
}
/**
@@ -91,10 +91,10 @@ class GuildBanManager extends CachedManager {
*/
fetch(options) {
if (!options) return this._fetchMany();
const user = this.client.users.resolveID(options);
const user = this.client.users.resolveId(options);
if (user) return this._fetchSingle({ user, cache: true });
if (options.user) {
options.user = this.client.users.resolveID(options.user);
options.user = this.client.users.resolveId(options.user);
}
if (!options.user) {
if ('cache' in options) return this._fetchMany(options.cache);
@@ -131,16 +131,16 @@ class GuildBanManager extends CachedManager {
* @param {BanOptions} [options] Options for the ban
* @returns {Promise<GuildMember|User|Snowflake>} Result object will be resolved as specifically as possible.
* If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot
* be resolved, the user ID will be the result.
* be resolved, the user id will be the result.
* @example
* // Ban a user by ID (or with a user/guild member object)
* // Ban a user by id (or with a user/guild member object)
* guild.bans.create('84484653687267328')
* .then(user => console.log(`Banned ${user.username ?? user.id ?? user} from ${guild.name}`))
* .catch(console.error);
*/
async create(user, options = { days: 0 }) {
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
const id = this.client.users.resolveID(user);
const id = this.client.users.resolveId(user);
if (!id) throw new Error('BAN_RESOLVE_ID', true);
await this.client.api
.guilds(this.guild.id)
@@ -165,13 +165,13 @@ class GuildBanManager extends CachedManager {
* @param {string} [reason] Reason for unbanning user
* @returns {Promise<User>}
* @example
* // Unban a user by ID (or with a user/guild member object)
* // Unban a user by id (or with a user/guild member object)
* guild.bans.remove('84484653687267328')
* .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
* .catch(console.error);
*/
async remove(user, reason) {
const id = this.client.users.resolveID(user);
const id = this.client.users.resolveId(user);
if (!id) throw new Error('BAN_RESOLVE_ID');
await this.client.api.guilds(this.guild.id).bans(id).delete({ reason });
return this.client.users.resolve(user);

View File

@@ -67,13 +67,13 @@ class GuildChannelManager extends CachedManager {
}
/**
* Resolves a GuildChannelResolvable to a channel ID string.
* Resolves a GuildChannelResolvable to a channel id.
* @param {GuildChannelResolvable} channel The GuildChannel resolvable to resolve
* @returns {?Snowflake}
*/
resolveID(channel) {
if (channel instanceof ThreadChannel) return super.resolveID(channel.id);
return super.resolveID(channel);
resolveId(channel) {
if (channel instanceof ThreadChannel) return super.resolveId(channel.id);
return super.resolveId(channel);
}
/**
@@ -119,7 +119,7 @@ class GuildChannelManager extends CachedManager {
name,
{ type, topic, nsfw, bitrate, userLimit, parent, permissionOverwrites, position, rateLimitPerUser, reason } = {},
) {
if (parent) parent = this.client.channels.resolveID(parent);
if (parent) parent = this.client.channels.resolveId(parent);
if (permissionOverwrites) {
permissionOverwrites = permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild));
}
@@ -144,7 +144,7 @@ class GuildChannelManager extends CachedManager {
/**
* Obtains one or more guild channels from Discord, or the channel cache if they're already available.
* @param {Snowflake} [id] ID of the channel
* @param {Snowflake} [id] The channel's id
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<?GuildChannel|Collection<Snowflake, GuildChannel>>}
* @example

View File

@@ -59,7 +59,7 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
}
data.roles = [];
for (const role of roles.values()) {
const resolvedRole = this.guild.roles.resolveID(role);
const resolvedRole = this.guild.roles.resolveId(role);
if (!resolvedRole) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'options.roles', role);
data.roles.push(resolvedRole);
}
@@ -73,7 +73,7 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
/**
* Obtains one or more emojis from Discord, or the emoji cache if they're already available.
* @param {Snowflake} [id] ID of the emoji
* @param {Snowflake} [id] The emoji's id
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<GuildEmoji|Collection<Snowflake, GuildEmoji>>}
* @example

View File

@@ -44,7 +44,7 @@ class GuildEmojiRoleManager extends DataManager {
const resolvedRoles = [];
for (const role of roleOrRoles.values()) {
const resolvedRole = this.guild.roles.resolveID(role);
const resolvedRole = this.guild.roles.resolveId(role);
if (!resolvedRole) {
return Promise.reject(new TypeError('INVALID_ELEMENT', 'Array or Collection', 'roles', role));
}
@@ -63,22 +63,22 @@ class GuildEmojiRoleManager extends DataManager {
remove(roleOrRoles) {
if (!Array.isArray(roleOrRoles) && !(roleOrRoles instanceof Collection)) roleOrRoles = [roleOrRoles];
const resolvedRoleIDs = [];
const resolvedRoleIds = [];
for (const role of roleOrRoles.values()) {
const roleID = this.guild.roles.resolveID(role);
if (!roleID) {
const roleId = this.guild.roles.resolveId(role);
if (!roleId) {
return Promise.reject(new TypeError('INVALID_ELEMENT', 'Array or Collection', 'roles', role));
}
resolvedRoleIDs.push(roleID);
resolvedRoleIds.push(roleId);
}
const newRoles = this.cache.keyArray().filter(id => !resolvedRoleIDs.includes(id));
const newRoles = this.cache.keyArray().filter(id => !resolvedRoleIds.includes(id));
return this.set(newRoles);
}
/**
* Sets the role(s) that can use this emoji.
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role IDs to apply
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role ids to apply
* @returns {Promise<GuildEmoji>}
* @example
* // Set the emoji's roles to a single role

View File

@@ -50,7 +50,7 @@ class GuildManager extends CachedManager {
/**
* Partial data for a Role.
* @typedef {Object} PartialRoleData
* @property {Snowflake|number} [id] The ID for this role, used to set channel overrides,
* @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
@@ -63,7 +63,7 @@ class GuildManager extends CachedManager {
/**
* Partial overwrite data.
* @typedef {Object} PartialOverwriteData
* @property {Snowflake|number} id The Role or User ID for this overwrite
* @property {Snowflake|number} id The {@link Role} or {@link User} id for this overwrite
* @property {string} [type] The type of this overwrite
* @property {PermissionResolvable} [allow] The permissions to allow
* @property {PermissionResolvable} [deny] The permissions to deny
@@ -72,9 +72,9 @@ class GuildManager extends CachedManager {
/**
* Partial data for a Channel.
* @typedef {Object} PartialChannelData
* @property {Snowflake|number} [id] The ID for this channel, used to set its parent,
* @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 {Snowflake|number} [parentId] The parent id for this channel
* @property {string} [type] The type of the channel
* @property {string} name The name of the channel
* @property {string} [topic] The topic of the text channel
@@ -108,14 +108,14 @@ class GuildManager extends CachedManager {
}
/**
* Resolves a GuildResolvable to a Guild ID string.
* @method resolveID
* Resolves a {@link GuildResolvable} to a {@link Guild} id string.
* @method resolveId
* @memberof GuildManager
* @instance
* @param {GuildResolvable} guild The guild resolvable to identify
* @returns {?Snowflake}
*/
resolveID(guild) {
resolveId(guild) {
if (
guild instanceof GuildChannel ||
guild instanceof GuildMember ||
@@ -123,15 +123,15 @@ class GuildManager extends CachedManager {
guild instanceof Role ||
(guild instanceof Invite && guild.guild)
) {
return super.resolveID(guild.guild.id);
return super.resolveId(guild.guild.id);
}
return super.resolveID(guild);
return super.resolveId(guild);
}
/**
* Options used to create a guild.
* @typedef {Object} GuildCreateOptions
* @property {Snowflake|number} [afkChannelID] The ID of the AFK channel
* @property {Snowflake|number} [afkChannelId] The AFK channel's id
* @property {number} [afkTimeout] The AFK timeout in seconds
* @property {PartialChannelData[]} [channels=[]] The channels for this guild
* @property {DefaultMessageNotifications} [defaultMessageNotifications] The default message notifications
@@ -140,7 +140,7 @@ class GuildManager extends CachedManager {
* @property {BufferResolvable|Base64Resolvable} [icon=null] The icon for the guild
* @property {PartialRoleData[]} [roles=[]] The roles for this guild,
* the first element of this array is used to change properties of the guild's everyone role.
* @property {Snowflake|number} [systemChannelID] The ID of the system channel
* @property {Snowflake|number} [systemChannelId] The system channel's id
* @property {SystemChannelFlagsResolvable} [systemChannelFlags] The flags of the system channel
* @property {VerificationLevel} [verificationLevel] The verification level for the guild
*/
@@ -155,14 +155,14 @@ class GuildManager extends CachedManager {
async create(
name,
{
afkChannelID,
afkChannelId,
afkTimeout,
channels = [],
defaultMessageNotifications,
explicitContentFilter,
icon = null,
roles = [],
systemChannelID,
systemChannelId,
systemChannelFlags,
verificationLevel,
} = {},
@@ -179,8 +179,8 @@ class GuildManager extends CachedManager {
}
for (const channel of channels) {
if (channel.type) channel.type = ChannelTypes[channel.type.toUpperCase()];
channel.parent_id = channel.parentID;
delete channel.parentID;
channel.parent_id = channel.parentId;
delete channel.parentId;
if (!channel.permissionOverwrites) continue;
for (const overwrite of channel.permissionOverwrites) {
if (overwrite.allow) overwrite.allow = Permissions.resolve(overwrite.allow).toString();
@@ -206,9 +206,9 @@ class GuildManager extends CachedManager {
explicit_content_filter: explicitContentFilter,
roles,
channels,
afk_channel_id: afkChannelID,
afk_channel_id: afkChannelId,
afk_timeout: afkTimeout,
system_channel_id: systemChannelID,
system_channel_id: systemChannelId,
system_channel_flags: systemChannelFlags,
},
})
@@ -245,18 +245,18 @@ class GuildManager extends CachedManager {
/**
* Options used to fetch multiple guilds.
* @typedef {Object} FetchGuildsOptions
* @property {Snowflake} [before] Get guilds before this guild ID
* @property {Snowflake} [after] Get guilds after this guild ID
* @property {Snowflake} [before] Get guilds before this guild id
* @property {Snowflake} [after] Get guilds after this guild id
* @property {number} [limit=100] Maximum number of guilds to request (1-100)
*/
/**
* Obtains one or multiple guilds from Discord, or the guild cache if it's already available.
* @param {GuildResolvable|FetchGuildOptions|FetchGuildsOptions} [options] ID of the guild or options
* @param {GuildResolvable|FetchGuildOptions|FetchGuildsOptions} [options] The guild's id or options
* @returns {Promise<Guild|Collection<Snowflake, OAuth2Guild>>}
*/
async fetch(options = {}) {
const id = this.resolveID(options) ?? this.resolveID(options.guild);
const id = this.resolveId(options) ?? this.resolveId(options.guild);
if (id) {
if (!options.force) {

View File

@@ -42,27 +42,27 @@ class GuildMemberManager extends CachedManager {
*/
/**
* Resolves a GuildMemberResolvable to a GuildMember object.
* Resolves a {@link GuildMemberResolvable} to a {@link GuildMember} object.
* @param {GuildMemberResolvable} member The user that is part of the guild
* @returns {?GuildMember}
*/
resolve(member) {
const memberResolvable = super.resolve(member);
if (memberResolvable) return memberResolvable;
const userResolvable = this.client.users.resolveID(member);
const userResolvable = this.client.users.resolveId(member);
if (userResolvable) return super.resolve(userResolvable);
return null;
}
/**
* Resolves a GuildMemberResolvable to a member ID string.
* Resolves a {@link GuildMemberResolvable} to a member id.
* @param {GuildMemberResolvable} member The user that is part of the guild
* @returns {?Snowflake}
*/
resolveID(member) {
const memberResolvable = super.resolveID(member);
resolveId(member) {
const memberResolvable = super.resolveId(member);
if (memberResolvable) return memberResolvable;
const userResolvable = this.client.users.resolveID(member);
const userResolvable = this.client.users.resolveId(member);
return this.cache.has(userResolvable) ? userResolvable : null;
}
@@ -123,14 +123,14 @@ class GuildMemberManager extends CachedManager {
*/
fetch(options) {
if (!options) return this._fetchMany();
const user = this.client.users.resolveID(options);
const user = this.client.users.resolveId(options);
if (user) return this._fetchSingle({ user, cache: true });
if (options.user) {
if (Array.isArray(options.user)) {
options.user = options.user.map(u => this.client.users.resolveID(u));
options.user = options.user.map(u => this.client.users.resolveId(u));
return this._fetchMany(options);
} else {
options.user = this.client.users.resolveID(options.user);
options.user = this.client.users.resolveId(options.user);
}
if (!options.limit && !options.withPresences) return this._fetchSingle(options);
}
@@ -164,7 +164,7 @@ class GuildMemberManager extends CachedManager {
* @returns {Promise<GuildMember>}
*/
async edit(user, data, reason) {
const id = this.client.users.resolveID(user);
const id = this.client.users.resolveId(user);
if (!id) throw new TypeError('INVALID_TYPE', 'user', 'UserResolvable');
// Clone the data object for immutability
@@ -234,7 +234,7 @@ class GuildMemberManager extends CachedManager {
const resolvedRoles = [];
for (const role of roles) {
const resolvedRole = this.guild.roles.resolveID(role);
const resolvedRole = this.guild.roles.resolveId(role);
if (!resolvedRole) {
return Promise.reject(new TypeError('INVALID_ELEMENT', 'Array', 'options.roles', role));
}
@@ -266,15 +266,15 @@ class GuildMemberManager extends CachedManager {
* @param {string} [reason] Reason for kicking
* @returns {Promise<GuildMember|User|Snowflake>} Result object will be resolved as specifically as possible.
* If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot
* be resolved, the user ID will be the result.
* be resolved, the user's id will be the result.
* @example
* // Kick a user by ID (or with a user/guild member object)
* // Kick a user by id (or with a user/guild member object)
* guild.members.kick('84484653687267328')
* .then(user => console.log(`Kicked ${user.username ?? user.id ?? user} from ${guild.name}`))
* .catch(console.error);
*/
async kick(user, reason) {
const id = this.client.users.resolveID(user);
const id = this.client.users.resolveId(user);
if (!id) return Promise.reject(new TypeError('INVALID_TYPE', 'user', 'UserResolvable'));
await this.client.api.guilds(this.guild.id).members(id).delete({ reason });
@@ -288,10 +288,10 @@ class GuildMemberManager extends CachedManager {
* @param {BanOptions} [options] Options for the ban
* @returns {Promise<GuildMember|User|Snowflake>} Result object will be resolved as specifically as possible.
* If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot
* be resolved, the user ID will be the result.
* be resolved, the user id will be the result.
* Internally calls the GuildBanManager#create method.
* @example
* // Ban a user by ID (or with a user/guild member object)
* // Ban a user by id (or with a user/guild member object)
* guild.members.ban('84484653687267328')
* .then(user => console.log(`Banned ${user.username ?? user.id ?? user} from ${guild.name}`))
* .catch(console.error);
@@ -307,7 +307,7 @@ class GuildMemberManager extends CachedManager {
* @returns {Promise<User>}
* Internally calls the GuildBanManager#remove method.
* @example
* // Unban a user by ID (or with a user/guild member object)
* // Unban a user by id (or with a user/guild member object)
* guild.members.unban('84484653687267328')
* .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
* .catch(console.error);

View File

@@ -84,7 +84,7 @@ class GuildMemberRoleManager extends DataManager {
*/
get botRole() {
if (!this.member.user.bot) return null;
return this.cache.find(role => role.tags?.botID === this.member.user.id) ?? null;
return this.cache.find(role => role.tags?.botId === this.member.user.id) ?? null;
}
/**
@@ -97,7 +97,7 @@ class GuildMemberRoleManager extends DataManager {
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
const resolvedRoles = [];
for (const role of roleOrRoles.values()) {
const resolvedRole = this.guild.roles.resolveID(role);
const resolvedRole = this.guild.roles.resolveId(role);
if (!resolvedRole) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'roles', role);
resolvedRoles.push(resolvedRole);
}
@@ -105,7 +105,7 @@ class GuildMemberRoleManager extends DataManager {
const newRoles = [...new Set(resolvedRoles.concat(...this.cache.values()))];
return this.set(newRoles, reason);
} else {
roleOrRoles = this.guild.roles.resolveID(roleOrRoles);
roleOrRoles = this.guild.roles.resolveId(roleOrRoles);
if (roleOrRoles === null) {
throw new TypeError('INVALID_TYPE', 'roles', 'Role, Snowflake or Array or Collection of Roles or Snowflakes');
}
@@ -128,7 +128,7 @@ class GuildMemberRoleManager extends DataManager {
if (roleOrRoles instanceof Collection || Array.isArray(roleOrRoles)) {
const resolvedRoles = [];
for (const role of roleOrRoles.values()) {
const resolvedRole = this.guild.roles.resolveID(role);
const resolvedRole = this.guild.roles.resolveId(role);
if (!resolvedRole) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'roles', role);
resolvedRoles.push(resolvedRole);
}
@@ -136,7 +136,7 @@ class GuildMemberRoleManager extends DataManager {
const newRoles = this.cache.filter(role => !resolvedRoles.includes(role.id));
return this.set(newRoles, reason);
} else {
roleOrRoles = this.guild.roles.resolveID(roleOrRoles);
roleOrRoles = this.guild.roles.resolveId(roleOrRoles);
if (roleOrRoles === null) {
throw new TypeError('INVALID_TYPE', 'roles', 'Role, Snwoflake or Array or Collection of Roles or Snowflakes');
}
@@ -152,7 +152,7 @@ class GuildMemberRoleManager extends DataManager {
/**
* Sets the roles applied to the member.
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role IDs to apply
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role ids to apply
* @param {string} [reason] Reason for applying the roles
* @returns {Promise<GuildMember>}
* @example

View File

@@ -36,16 +36,16 @@ class MessageManager extends CachedManager {
* `after` are mutually exclusive. All the parameters are optional.
* @typedef {Object} ChannelLogsQueryOptions
* @property {number} [limit=50] Number of messages to acquire
* @property {Snowflake} [before] ID of a message to get the messages that were posted before it
* @property {Snowflake} [after] ID of a message to get the messages that were posted after it
* @property {Snowflake} [around] ID of a message to get the messages that were posted around it
* @property {Snowflake} [before] The message's id to get the messages that were posted before it
* @property {Snowflake} [after] The message's id to get the messages that were posted after it
* @property {Snowflake} [around] The message's id to get the messages that were posted around it
*/
/**
* Gets a message, or messages, from this channel.
* <info>The returned Collection does not contain reaction users of the messages if they were not cached.
* Those need to be fetched separately in such a case.</info>
* @param {Snowflake|ChannelLogsQueryOptions} [message] The ID of the message to fetch, or query parameters.
* @param {Snowflake|ChannelLogsQueryOptions} [message] The id of the message to fetch, or query parameters.
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<Message>|Promise<Collection<Snowflake, Message>>}
* @example
@@ -59,7 +59,7 @@ class MessageManager extends CachedManager {
* .then(messages => console.log(`Received ${messages.size} messages`))
* .catch(console.error);
* @example
* // Get messages and filter by user ID
* // Get messages and filter by user id
* channel.messages.fetch()
* .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
* .catch(console.error);
@@ -96,7 +96,7 @@ class MessageManager extends CachedManager {
*/
/**
* Resolves a MessageResolvable to a Message object.
* Resolves a {@link MessageResolvable} to a {@link Message} object.
* @method resolve
* @memberof MessageManager
* @instance
@@ -105,8 +105,8 @@ class MessageManager extends CachedManager {
*/
/**
* Resolves a MessageResolvable to a Message ID string.
* @method resolveID
* Resolves a {@link MessageResolvable} to a {@link Message} id.
* @method resolveId
* @memberof MessageManager
* @instance
* @param {MessageResolvable} message The message resolvable to resolve
@@ -120,8 +120,8 @@ class MessageManager extends CachedManager {
* @returns {Promise<Message>}
*/
async edit(message, options) {
const messageID = this.resolveID(message);
if (!messageID) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
const messageId = this.resolveId(message);
if (!messageId) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
const { data, files } = await (options instanceof MessagePayload
? options
@@ -129,9 +129,9 @@ class MessageManager extends CachedManager {
)
.resolveData()
.resolveFiles();
const d = await this.client.api.channels[this.channel.id].messages[messageID].patch({ data, files });
const d = await this.client.api.channels[this.channel.id].messages[messageId].patch({ data, files });
const existing = this.cache.get(messageID);
const existing = this.cache.get(messageId);
if (existing) {
const clone = existing._clone();
clone._patch(d);
@@ -146,7 +146,7 @@ class MessageManager extends CachedManager {
* @returns {Promise<Message>}
*/
async crosspost(message) {
message = this.resolveID(message);
message = this.resolveId(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
const data = await this.client.api.channels(this.channel.id).messages(message).crosspost.post();
@@ -159,7 +159,7 @@ class MessageManager extends CachedManager {
* @returns {Promise<void>}
*/
async pin(message) {
message = this.resolveID(message);
message = this.resolveId(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
await this.client.api.channels(this.channel.id).pins(message).put();
@@ -171,7 +171,7 @@ class MessageManager extends CachedManager {
* @returns {Promise<void>}
*/
async unpin(message) {
message = this.resolveID(message);
message = this.resolveId(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
await this.client.api.channels(this.channel.id).pins(message).delete();
@@ -184,7 +184,7 @@ class MessageManager extends CachedManager {
* @returns {Promise<void>}
*/
async react(message, emoji) {
message = this.resolveID(message);
message = this.resolveId(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
emoji = this.client.emojis.resolveIdentifier(emoji);
@@ -200,19 +200,19 @@ class MessageManager extends CachedManager {
* @returns {Promise<void>}
*/
async delete(message) {
message = this.resolveID(message);
message = this.resolveId(message);
if (!message) throw new TypeError('INVALID_TYPE', 'message', 'MessageResolvable');
await this.client.api.channels(this.channel.id).messages(message).delete();
}
async _fetchId(messageID, cache, force) {
async _fetchId(messageId, cache, force) {
if (!force) {
const existing = this.cache.get(messageID);
const existing = this.cache.get(messageId);
if (existing && !existing.partial) return existing;
}
const data = await this.client.api.channels[this.channel.id].messages[messageID].get();
const data = await this.client.api.channels[this.channel.id].messages[messageId].get();
return this.add(data, cache);
}

View File

@@ -71,7 +71,7 @@ class PermissionOverwriteManager extends CachedManager {
* @private
*/
async upsert(userOrRole, options, overwriteOptions = {}, existing) {
let userOrRoleID = this.channel.guild.roles.resolveID(userOrRole) ?? this.client.users.resolveID(userOrRole);
let userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
let { type, reason } = overwriteOptions;
if (typeof type !== 'number') {
userOrRole = this.channel.guild.roles.resolve(userOrRole) ?? this.client.users.resolve(userOrRole);
@@ -83,9 +83,9 @@ class PermissionOverwriteManager extends CachedManager {
await this.client.api
.channels(this.channel.id)
.permissions(userOrRoleID)
.permissions(userOrRoleId)
.put({
data: { id: userOrRoleID, type, allow, deny },
data: { id: userOrRoleId, type, allow, deny },
reason,
});
return this.channel;
@@ -124,7 +124,7 @@ class PermissionOverwriteManager extends CachedManager {
* .catch(console.error);
*/
edit(userOrRole, options, overwriteOptions) {
userOrRole = this.channel.guild.roles.resolveID(userOrRole) ?? this.client.users.resolveID(userOrRole);
userOrRole = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
const existing = this.cache.get(userOrRole);
return this.upsert(userOrRole, options, overwriteOptions, existing);
}
@@ -136,10 +136,10 @@ class PermissionOverwriteManager extends CachedManager {
* @returns {GuildChannel}
*/
async delete(userOrRole, reason) {
const userOrRoleID = this.channel.guild.roles.resolveID(userOrRole) ?? this.client.users.resolveID(userOrRole);
if (!userOrRoleID) throw new TypeError('INVALID_TYPE', 'parameter', 'User nor a Role');
const userOrRoleId = this.channel.guild.roles.resolveId(userOrRole) ?? this.client.users.resolveId(userOrRole);
if (!userOrRoleId) throw new TypeError('INVALID_TYPE', 'parameter', 'User nor a Role');
await this.client.api.channels(this.channel.id).permissions(userOrRoleID).delete({ reason });
await this.client.api.channels(this.channel.id).permissions(userOrRoleId).delete({ reason });
return this.channel;
}
}

View File

@@ -32,26 +32,26 @@ class PresenceManager extends CachedManager {
*/
/**
* Resolves a PresenceResolvable to a Presence object.
* Resolves a {@link PresenceResolvable} to a {@link Presence} object.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Presence}
*/
resolve(presence) {
const presenceResolvable = super.resolve(presence);
if (presenceResolvable) return presenceResolvable;
const UserResolvable = this.client.users.resolveID(presence);
const UserResolvable = this.client.users.resolveId(presence);
return super.resolve(UserResolvable);
}
/**
* Resolves a PresenceResolvable to a Presence ID string.
* Resolves a {@link PresenceResolvable} to a {@link Presence} id.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Snowflake}
*/
resolveID(presence) {
const presenceResolvable = super.resolveID(presence);
resolveId(presence) {
const presenceResolvable = super.resolveId(presence);
if (presenceResolvable) return presenceResolvable;
const userResolvable = this.client.users.resolveID(presence);
const userResolvable = this.client.users.resolveId(presence);
return this.cache.has(userResolvable) ? userResolvable : null;
}
}

View File

@@ -36,7 +36,7 @@ class ReactionManager extends CachedManager {
*/
/**
* Resolves a MessageReactionResolvable to a MessageReaction object.
* Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} object.
* @method resolve
* @memberof ReactionManager
* @instance
@@ -45,8 +45,8 @@ class ReactionManager extends CachedManager {
*/
/**
* Resolves a MessageReactionResolvable to a MessageReaction ID string.
* @method resolveID
* Resolves a {@link MessageReactionResolvable} to a {@link MessageReaction} id.
* @method resolveId
* @memberof ReactionManager
* @instance
* @param {MessageReactionResolvable} reaction The MessageReaction to resolve

View File

@@ -34,7 +34,7 @@ class ReactionUserManager extends CachedManager {
*/
/**
* Fetches all the users that gave this reaction. Resolves with a collection of users, mapped by their IDs.
* Fetches all the users that gave this reaction. Resolves with a collection of users, mapped by their ids.
* @param {FetchReactionUsersOptions} [options] Options for fetching the users
* @returns {Promise<Collection<Snowflake, User>>}
*/
@@ -58,11 +58,11 @@ class ReactionUserManager extends CachedManager {
* @returns {Promise<MessageReaction>}
*/
remove(user = this.client.user) {
const userID = this.client.users.resolveID(user);
if (!userID) return Promise.reject(new Error('REACTION_RESOLVE_USER'));
const userId = this.client.users.resolveId(user);
if (!userId) return Promise.reject(new Error('REACTION_RESOLVE_USER'));
const message = this.reaction.message;
return this.client.api.channels[message.channel.id].messages[message.id].reactions[this.reaction.emoji.identifier][
userID === this.client.user.id ? '@me' : userID
userId === this.client.user.id ? '@me' : userId
]
.delete()
.then(() => this.reaction);

View File

@@ -34,7 +34,7 @@ class RoleManager extends CachedManager {
/**
* Obtains a role from Discord, or the role cache if they're already available.
* @param {Snowflake} [id] ID of the role
* @param {Snowflake} [id] The role's id
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<?Role|Collection<Snowflake, Role>>}
* @example
@@ -69,7 +69,7 @@ class RoleManager extends CachedManager {
*/
/**
* Resolves a RoleResolvable to a Role object.
* Resolves a {@link RoleResolvable} to a {@link Role} object.
* @method resolve
* @memberof RoleManager
* @instance
@@ -78,8 +78,8 @@ class RoleManager extends CachedManager {
*/
/**
* Resolves a RoleResolvable to a role ID string.
* @method resolveID
* Resolves a {@link RoleResolvable} to a {@link Role} id.
* @method resolveId
* @memberof RoleManager
* @instance
* @param {RoleResolvable} role The role resolvable to resolve
@@ -199,9 +199,9 @@ class RoleManager extends CachedManager {
* @returns {?Role}
*/
botRoleFor(user) {
const userID = this.client.users.resolveID(user);
if (!userID) return null;
return this.cache.find(role => role.tags?.botID === userID) ?? null;
const userId = this.client.users.resolveId(user);
if (!userId) return null;
return this.cache.find(role => role.tags?.botId === userId) ?? null;
}
/**

View File

@@ -48,8 +48,8 @@ class StageInstanceManager extends CachedManager {
* .catch(console.error);
*/
async create(channel, options) {
const channelID = this.guild.channels.resolveID(channel);
if (!channelID) throw new Error('STAGE_CHANNEL_RESOLVE');
const channelId = this.guild.channels.resolveId(channel);
if (!channelId) throw new Error('STAGE_CHANNEL_RESOLVE');
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
let { topic, privacyLevel } = options;
@@ -57,7 +57,7 @@ class StageInstanceManager extends CachedManager {
const data = await this.client.api['stage-instances'].post({
data: {
channel_id: channelID,
channel_id: channelId,
topic,
privacy_level: privacyLevel,
},
@@ -78,15 +78,15 @@ class StageInstanceManager extends CachedManager {
* .catch(console.error);
*/
async fetch(channel, { cache = true, force = false } = {}) {
const channelID = this.guild.channels.resolveID(channel);
if (!channelID) throw new Error('STAGE_CHANNEL_RESOLVE');
const channelId = this.guild.channels.resolveId(channel);
if (!channelId) throw new Error('STAGE_CHANNEL_RESOLVE');
if (!force) {
const existing = this.cache.find(stageInstance => stageInstance.channelID === channelID);
const existing = this.cache.find(stageInstance => stageInstance.channelId === channelId);
if (existing) return existing;
}
const data = await this.client.api('stage-instances', channelID).get();
const data = await this.client.api('stage-instances', channelId).get();
return this.add(data, cache);
}
@@ -110,14 +110,14 @@ class StageInstanceManager extends CachedManager {
*/
async edit(channel, options) {
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
const channelID = this.guild.channels.resolveID(channel);
if (!channelID) throw new Error('STAGE_CHANNEL_RESOLVE');
const channelId = this.guild.channels.resolveId(channel);
if (!channelId) throw new Error('STAGE_CHANNEL_RESOLVE');
let { topic, privacyLevel } = options;
if (privacyLevel) privacyLevel = typeof privacyLevel === 'number' ? privacyLevel : PrivacyLevels[privacyLevel];
const data = await this.client.api('stage-instances', channelID).patch({
const data = await this.client.api('stage-instances', channelId).patch({
data: {
topic,
privacy_level: privacyLevel,
@@ -139,10 +139,10 @@ class StageInstanceManager extends CachedManager {
* @returns {Promise<void>}
*/
async delete(channel) {
const channelID = this.guild.channels.resolveID(channel);
if (!channelID) throw new Error('STAGE_CHANNEL_RESOLVE');
const channelId = this.guild.channels.resolveId(channel);
if (!channelId) throw new Error('STAGE_CHANNEL_RESOLVE');
await this.client.api('stage-instances', channelID).delete();
await this.client.api('stage-instances', channelId).delete();
}
}

View File

@@ -42,7 +42,7 @@ class ThreadManager extends CachedManager {
*/
/**
* Resolves a ThreadChannelResolvable to a Thread Channel object.
* Resolves a {@link ThreadChannelResolvable} to a {@link ThreadChannel} object.
* @method resolve
* @memberof ThreadManager
* @instance
@@ -51,8 +51,8 @@ class ThreadManager extends CachedManager {
*/
/**
* Resolves a ThreadChannelResolvable to a thread channel ID string.
* @method resolveID
* Resolves a {@link ThreadChannelResolvable} to a {@link ThreadChannel} id.
* @method resolveId
* @memberof ThreadManager
* @instance
* @param {ThreadChannelResolvable} thread The ThreadChannel resolvable to resolve
@@ -116,9 +116,9 @@ class ThreadManager extends CachedManager {
}
let resolvedType = this.channel.type === 'news' ? ChannelTypes.NEWS_THREAD : ChannelTypes.PUBLIC_THREAD;
if (startMessage) {
const startMessageID = this.channel.messages.resolveID(startMessage);
if (!startMessageID) throw new TypeError('INVALID_TYPE', 'startMessage', 'MessageResolvable');
path = path.messages(startMessageID);
const startMessageId = this.channel.messages.resolveId(startMessage);
if (!startMessageId) throw new TypeError('INVALID_TYPE', 'startMessage', 'MessageResolvable');
path = path.messages(startMessageId);
} else if (this.channel.type !== 'news') {
resolvedType = typeof type === 'string' ? ChannelTypes[type.toUpperCase()] : type ?? resolvedType;
}
@@ -157,7 +157,7 @@ class ThreadManager extends CachedManager {
*/
fetch(options, { cache = true, force = false } = {}) {
if (!options) return this.fetchActive(cache);
const channel = this.client.channels.resolveID(options);
const channel = this.client.channels.resolveId(options);
if (channel) return this.client.channels.fetch(channel, cache, force);
if (options.archived) {
return this.fetchArchived(options.archived, cache);
@@ -206,7 +206,7 @@ class ThreadManager extends CachedManager {
let id;
if (typeof before !== 'undefined') {
if (before instanceof ThreadChannel || /^\d{16,19}$/.test(String(before))) {
id = this.resolveID(before);
id = this.resolveId(before);
timestamp = this.resolve(before)?.archivedAt?.toISOString();
} else {
try {

View File

@@ -44,27 +44,27 @@ class ThreadMemberManager extends CachedManager {
*/
/**
* Resolves a ThreadMemberResolvable to a ThreadMember object.
* Resolves a {@link ThreadMemberResolvable} to a {@link ThreadMember} object.
* @param {ThreadMemberResolvable} member The user that is part of the thread
* @returns {?GuildMember}
*/
resolve(member) {
const memberResolvable = super.resolve(member);
if (memberResolvable) return memberResolvable;
const userResolvable = this.client.users.resolveID(member);
const userResolvable = this.client.users.resolveId(member);
if (userResolvable) return super.resolve(userResolvable);
return null;
}
/**
* Resolves a ThreadMemberResolvable to a thread member ID string.
* Resolves a {@link ThreadMemberResolvable} to a {@link ThreadMember} id string.
* @param {ThreadMemberResolvable} member The user that is part of the guild
* @returns {?Snowflake}
*/
resolveID(member) {
const memberResolvable = super.resolveID(member);
resolveId(member) {
const memberResolvable = super.resolveId(member);
if (memberResolvable) return memberResolvable;
const userResolvable = this.client.users.resolveID(member);
const userResolvable = this.client.users.resolveId(member);
return this.cache.has(userResolvable) ? userResolvable : null;
}
@@ -75,7 +75,7 @@ class ThreadMemberManager extends CachedManager {
* @returns {Promise<Snowflake>}
*/
add(member, reason) {
const id = member === '@me' ? member : this.client.users.resolveID(member);
const id = member === '@me' ? member : this.client.users.resolveId(member);
if (!id) return Promise.reject(new TypeError('INVALID_TYPE', 'member', 'UserResolvable'));
return this.client.api
.channels(this.thread.id, 'thread-members', id)

View File

@@ -32,7 +32,7 @@ class UserManager extends CachedManager {
*/
/**
* Resolves a UserResolvable to a User object.
* Resolves a {@link UserResolvable} to a {@link User} object.
* @param {UserResolvable} user The UserResolvable to identify
* @returns {?User}
*/
@@ -43,20 +43,20 @@ class UserManager extends CachedManager {
}
/**
* Resolves a UserResolvable to a user ID string.
* Resolves a {@link UserResolvable} to a {@link User} id.
* @param {UserResolvable} user The UserResolvable to identify
* @returns {?Snowflake}
*/
resolveID(user) {
resolveId(user) {
if (user instanceof ThreadMember) return user.id;
if (user instanceof GuildMember) return user.user.id;
if (user instanceof Message) return user.author.id;
return super.resolveID(user);
return super.resolveId(user);
}
/**
* Obtains a user from Discord, or the user cache if it's already available.
* @param {Snowflake} id ID of the user
* @param {Snowflake} id The user's id
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<User>}
*/