mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
Remove unnecessary array conversions
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -251,13 +251,13 @@ class Client extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* This shouldn't really be necessary to most developers as it is automatically invoked every 30 seconds, however
|
* This shouldn't really be necessary to most developers as it is automatically invoked every 30 seconds, however
|
||||||
* if you wish to force a sync of Guild data, you can use this. Only applicable to user accounts.
|
* if you wish to force a sync of Guild data, you can use this. Only applicable to user accounts.
|
||||||
* @param {Guild[]} [guilds=this.guilds.array()] An array of guilds to sync
|
* @param {Guild[]|Collection<string, Guild>} [guilds=this.guilds] An array or collection of guilds to sync
|
||||||
*/
|
*/
|
||||||
syncGuilds(guilds = this.guilds.array()) {
|
syncGuilds(guilds = this.guilds) {
|
||||||
if (!this.user.bot) {
|
if (!this.user.bot) {
|
||||||
this.ws.send({
|
this.ws.send({
|
||||||
op: 12,
|
op: 12,
|
||||||
d: guilds.map(g => g.id),
|
d: guilds instanceof Collection ? guilds.keyArray() : guilds.map(g => g.id),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class WebSocketManager extends EventEmitter {
|
|||||||
if (unavailableCount === 0) {
|
if (unavailableCount === 0) {
|
||||||
this.status = Constants.Status.NEARLY;
|
this.status = Constants.Status.NEARLY;
|
||||||
if (this.client.options.fetchAllMembers) {
|
if (this.client.options.fetchAllMembers) {
|
||||||
const promises = this.client.guilds.array().map(g => g.fetchMembers());
|
const promises = this.client.guilds.map(g => g.fetchMembers());
|
||||||
Promise.all(promises).then(() => this._emitReady()).catch(e => {
|
Promise.all(promises).then(() => this._emitReady()).catch(e => {
|
||||||
this.client.emit(Constants.Events.WARN, 'Error in pre-ready guild member fetching');
|
this.client.emit(Constants.Events.WARN, 'Error in pre-ready guild member fetching');
|
||||||
this.client.emit(Constants.Events.ERROR, e);
|
this.client.emit(Constants.Events.ERROR, e);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class Emoji {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
* @example
|
* @example
|
||||||
* // send an emoji:
|
* // send an emoji:
|
||||||
* const emoji = guild.emojis.array()[0];
|
* const emoji = guild.emojis.first();
|
||||||
* msg.reply(`Hello! ${emoji}`);
|
* msg.reply(`Hello! ${emoji}`);
|
||||||
*/
|
*/
|
||||||
toString() {
|
toString() {
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ class GroupDMChannel extends Channel {
|
|||||||
this.ownerID === channel.ownerID;
|
this.ownerID === channel.ownerID;
|
||||||
|
|
||||||
if (equal) {
|
if (equal) {
|
||||||
const thisIDs = this.recipients.array().map(r => r.id);
|
const thisIDs = this.recipients.keyArray();
|
||||||
const otherIDs = channel.recipients.map(r => r.id);
|
const otherIDs = channel.recipients.keyArray();
|
||||||
return arraysEqual(thisIDs, otherIDs);
|
return arraysEqual(thisIDs, otherIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -316,8 +316,9 @@ class TextBasedChannel {
|
|||||||
* @returns {Collection<string, Message>}
|
* @returns {Collection<string, Message>}
|
||||||
*/
|
*/
|
||||||
bulkDelete(messages) {
|
bulkDelete(messages) {
|
||||||
if (messages instanceof Collection) messages = messages.array();
|
if (!(messages instanceof Array || messages instanceof Collection)) {
|
||||||
if (!(messages instanceof Array)) return Promise.reject(new TypeError('Messages must be an Array or Collection.'));
|
return Promise.reject(new TypeError('Messages must be an Array or Collection.'));
|
||||||
|
}
|
||||||
const messageIDs = messages.map(m => m.id);
|
const messageIDs = messages.map(m => m.id);
|
||||||
return this.client.rest.methods.bulkDeleteMessages(this, messageIDs);
|
return this.client.rest.methods.bulkDeleteMessages(this, messageIDs);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user