mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
refactor(Managers): rename add to _add (#6060)
This commit is contained in:
@@ -101,7 +101,7 @@ class BaseGuild extends Base {
|
||||
*/
|
||||
async fetch() {
|
||||
const data = await this.client.api.guilds(this.id).get({ query: { with_counts: true } });
|
||||
return this.client.guilds.add(data);
|
||||
return this.client.guilds._add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,7 +60,7 @@ class ClientApplication extends Application {
|
||||
this.owner = data.team
|
||||
? new Team(this.client, data.team)
|
||||
: data.owner
|
||||
? this.client.users.add(data.owner)
|
||||
? this.client.users._add(data.owner)
|
||||
: this.owner ?? null;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,16 +112,16 @@ class CommandInteraction extends Interaction {
|
||||
|
||||
if (resolved) {
|
||||
const user = resolved.users?.[option.value];
|
||||
if (user) result.user = this.client.users.add(user);
|
||||
if (user) result.user = this.client.users._add(user);
|
||||
|
||||
const member = resolved.members?.[option.value];
|
||||
if (member) result.member = this.guild?.members.add({ user, ...member }) ?? member;
|
||||
if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member;
|
||||
|
||||
const channel = resolved.channels?.[option.value];
|
||||
if (channel) result.channel = this.client.channels.add(channel, this.guild) ?? channel;
|
||||
if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel;
|
||||
|
||||
const role = resolved.roles?.[option.value];
|
||||
if (role) result.role = this.guild?.roles.add(role) ?? role;
|
||||
if (role) result.role = this.guild?.roles._add(role) ?? role;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -34,7 +34,7 @@ class DMChannel extends Channel {
|
||||
* The recipient on the other end of the DM
|
||||
* @type {User}
|
||||
*/
|
||||
this.recipient = this.client.users.add(data.recipients[0]);
|
||||
this.recipient = this.client.users._add(data.recipients[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -343,24 +343,24 @@ class Guild extends AnonymousGuild {
|
||||
if (data.channels) {
|
||||
this.channels.cache.clear();
|
||||
for (const rawChannel of data.channels) {
|
||||
this.client.channels.add(rawChannel, this);
|
||||
this.client.channels._add(rawChannel, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.threads) {
|
||||
for (const rawThread of data.threads) {
|
||||
this.client.channels.add(rawThread, this);
|
||||
this.client.channels._add(rawThread, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.roles) {
|
||||
this.roles.cache.clear();
|
||||
for (const role of data.roles) this.roles.add(role);
|
||||
for (const role of data.roles) this.roles._add(role);
|
||||
}
|
||||
|
||||
if (data.members) {
|
||||
this.members.cache.clear();
|
||||
for (const guildUser of data.members) this.members.add(guildUser);
|
||||
for (const guildUser of data.members) this.members._add(guildUser);
|
||||
}
|
||||
|
||||
if (data.owner_id) {
|
||||
@@ -373,21 +373,21 @@ class Guild extends AnonymousGuild {
|
||||
|
||||
if (data.presences) {
|
||||
for (const presence of data.presences) {
|
||||
this.presences.add(Object.assign(presence, { guild: this }));
|
||||
this.presences._add(Object.assign(presence, { guild: this }));
|
||||
}
|
||||
}
|
||||
|
||||
if (data.stage_instances) {
|
||||
this.stageInstances.cache.clear();
|
||||
for (const stageInstance of data.stage_instances) {
|
||||
this.stageInstances.add(stageInstance);
|
||||
this.stageInstances._add(stageInstance);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.voice_states) {
|
||||
this.voiceStates.cache.clear();
|
||||
for (const voiceState of data.voice_states) {
|
||||
this.voiceStates.add(voiceState);
|
||||
this.voiceStates._add(voiceState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ class Guild extends AnonymousGuild {
|
||||
* @type {GuildEmojiManager}
|
||||
*/
|
||||
this.emojis = new GuildEmojiManager(this);
|
||||
if (data.emojis) for (const emoji of data.emojis) this.emojis.add(emoji);
|
||||
if (data.emojis) for (const emoji of data.emojis) this.emojis._add(emoji);
|
||||
} else if (data.emojis) {
|
||||
this.client.actions.GuildEmojisUpdate.handle({
|
||||
guild_id: this.id,
|
||||
@@ -513,7 +513,7 @@ class Guild extends AnonymousGuild {
|
||||
return (
|
||||
this.members.resolve(this.client.user.id) ??
|
||||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
|
||||
? this.members.add({ user: { id: this.client.user.id } }, true)
|
||||
? this.members._add({ user: { id: this.client.user.id } }, true)
|
||||
: null)
|
||||
);
|
||||
}
|
||||
@@ -759,7 +759,7 @@ class Guild extends AnonymousGuild {
|
||||
}
|
||||
const data = await this.client.api.guilds(this.id).members(user).put({ data: options });
|
||||
// Data is an empty buffer if the member is already part of the guild.
|
||||
return data instanceof Buffer ? this.members.fetch(user) : this.members.add(data);
|
||||
return data instanceof Buffer ? this.members.fetch(user) : this.members._add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -140,7 +140,7 @@ const Actions = {
|
||||
*/
|
||||
class GuildAuditLogs {
|
||||
constructor(guild, data) {
|
||||
if (data.users) for (const user of data.users) guild.client.users.add(user);
|
||||
if (data.users) for (const user of data.users) guild.client.users._add(user);
|
||||
/**
|
||||
* Cached webhooks
|
||||
* @type {Collection<Snowflake, Webhook>}
|
||||
@@ -340,7 +340,7 @@ class GuildAuditLogsEntry {
|
||||
*/
|
||||
this.executor = data.user_id
|
||||
? guild.client.options.partials.includes(PartialTypes.USER)
|
||||
? guild.client.users.add({ id: data.user_id })
|
||||
? guild.client.users._add({ id: data.user_id })
|
||||
: guild.client.users.cache.get(data.user_id)
|
||||
: null;
|
||||
|
||||
@@ -450,7 +450,7 @@ class GuildAuditLogsEntry {
|
||||
// MEMBER_DISCONNECT and similar types do not provide a target_id.
|
||||
} else if (targetType === Targets.USER && data.target_id) {
|
||||
this.target = guild.client.options.partials.includes(PartialTypes.USER)
|
||||
? guild.client.users.add({ id: data.target_id })
|
||||
? guild.client.users._add({ id: data.target_id })
|
||||
: guild.client.users.cache.get(data.target_id);
|
||||
} else if (targetType === Targets.GUILD) {
|
||||
this.target = guild.client.guilds.cache.get(data.target_id);
|
||||
|
||||
@@ -29,7 +29,7 @@ class GuildBan extends Base {
|
||||
* The user this ban applies to
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user, true);
|
||||
this.user = this.client.users._add(data.user, true);
|
||||
|
||||
if ('reason' in data) {
|
||||
/**
|
||||
|
||||
@@ -85,7 +85,7 @@ class GuildChannel extends Channel {
|
||||
if ('permission_overwrites' in data) {
|
||||
this.permissionOverwrites.cache.clear();
|
||||
for (const overwrite of data.permission_overwrites) {
|
||||
this.permissionOverwrites.add(overwrite);
|
||||
this.permissionOverwrites._add(overwrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class GuildEmoji extends BaseGuildEmoji {
|
||||
_patch(data) {
|
||||
super._patch(data);
|
||||
|
||||
if (data.user) this.author = this.client.users.add(data.user);
|
||||
if (data.user) this.author = this.client.users._add(data.user);
|
||||
if (data.roles) this._roles = data.roles;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class GuildMember extends Base {
|
||||
* The user that this guild member instance represents
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user, true);
|
||||
this.user = this.client.users._add(data.user, true);
|
||||
}
|
||||
|
||||
if ('nick' in data) this.nickname = data.nick;
|
||||
|
||||
@@ -59,7 +59,7 @@ class GuildTemplate extends Base {
|
||||
* The user that created this template
|
||||
* @type {User}
|
||||
*/
|
||||
this.creator = this.client.users.add(data.creator);
|
||||
this.creator = this.client.users._add(data.creator);
|
||||
|
||||
/**
|
||||
* The time of when this template was created at
|
||||
@@ -130,7 +130,7 @@ class GuildTemplate extends Base {
|
||||
client.incrementMaxListeners();
|
||||
client.on(Events.GUILD_CREATE, handleGuild);
|
||||
|
||||
const timeout = client.setTimeout(() => resolveGuild(client.guilds.add(data)), 10000);
|
||||
const timeout = client.setTimeout(() => resolveGuild(client.guilds._add(data)), 10000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class Integration extends Base {
|
||||
* The user for this integration
|
||||
* @type {?User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user);
|
||||
this.user = this.client.users._add(data.user);
|
||||
} else {
|
||||
this.user = null;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class IntegrationApplication extends Application {
|
||||
* The bot user for this application
|
||||
* @type {?User}
|
||||
*/
|
||||
this.bot = data.bot ? this.client.users.add(data.bot) : this.bot ?? null;
|
||||
this.bot = data.bot ? this.client.users._add(data.bot) : this.bot ?? null;
|
||||
|
||||
/**
|
||||
* The url of the application's terms of service
|
||||
|
||||
@@ -54,13 +54,13 @@ class Interaction extends Base {
|
||||
* The user which sent this interaction
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user ?? data.member.user);
|
||||
this.user = this.client.users._add(data.user ?? data.member.user);
|
||||
|
||||
/**
|
||||
* If this interaction was sent in a guild, the member which sent it
|
||||
* @type {?(GuildMember|APIGuildMember)}
|
||||
*/
|
||||
this.member = data.member ? this.guild?.members.add(data.member) ?? data.member : null;
|
||||
this.member = data.member ? this.guild?.members._add(data.member) ?? data.member : null;
|
||||
|
||||
/**
|
||||
* The version
|
||||
|
||||
@@ -76,13 +76,13 @@ class Invite extends Base {
|
||||
* The user who created this invite
|
||||
* @type {?User}
|
||||
*/
|
||||
this.inviter = data.inviter ? this.client.users.add(data.inviter) : null;
|
||||
this.inviter = data.inviter ? this.client.users._add(data.inviter) : null;
|
||||
|
||||
/**
|
||||
* The user whose stream to display for this voice channel stream invite
|
||||
* @type {?User}
|
||||
*/
|
||||
this.targetUser = data.target_user ? this.client.users.add(data.target_user) : null;
|
||||
this.targetUser = data.target_user ? this.client.users._add(data.target_user) : null;
|
||||
|
||||
/**
|
||||
* The embedded application to open for this voice channel embedded application invite
|
||||
@@ -109,7 +109,7 @@ class Invite extends Base {
|
||||
* The channel the invite is for
|
||||
* @type {Channel}
|
||||
*/
|
||||
this.channel = this.client.channels.add(data.channel, this.guild, false);
|
||||
this.channel = this.client.channels._add(data.channel, this.guild, false);
|
||||
|
||||
/**
|
||||
* The timestamp the invite was created at
|
||||
|
||||
@@ -53,7 +53,7 @@ class InviteStageInstance extends Base {
|
||||
|
||||
this.members.clear();
|
||||
for (const rawMember of data.members) {
|
||||
const member = this.guild.members.add(rawMember);
|
||||
const member = this.guild.members._add(rawMember);
|
||||
this.members.set(member.id, member);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class Message extends Base {
|
||||
* The author of the message
|
||||
* @type {?User}
|
||||
*/
|
||||
this.author = this.client.users.add(data.author, !data.webhook_id);
|
||||
this.author = this.client.users._add(data.author, !data.webhook_id);
|
||||
} else if (!this.author) {
|
||||
this.author = null;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ class Message extends Base {
|
||||
* The thread started by this message
|
||||
* @type {?ThreadChannel}
|
||||
*/
|
||||
this.thread = this.client.channels.add(data.thread);
|
||||
this.thread = this.client.channels._add(data.thread);
|
||||
} else if (!this.thread) {
|
||||
this.thread = null;
|
||||
}
|
||||
@@ -182,7 +182,7 @@ class Message extends Base {
|
||||
this.reactions = new ReactionManager(this);
|
||||
if (data.reactions?.length > 0) {
|
||||
for (const reaction of data.reactions) {
|
||||
this.reactions.add(reaction);
|
||||
this.reactions._add(reaction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ class Message extends Base {
|
||||
if (this.member && data.member) {
|
||||
this.member._patch(data.member);
|
||||
} else if (data.member && this.guild && this.author) {
|
||||
this.guild.members.add(Object.assign(data.member, { user: this.author }));
|
||||
this.guild.members._add(Object.assign(data.member, { user: this.author }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +261,7 @@ class Message extends Base {
|
||||
: null;
|
||||
|
||||
if (data.referenced_message) {
|
||||
this.channel.messages.add(data.referenced_message);
|
||||
this.channel.messages._add(data.referenced_message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,7 +282,7 @@ class Message extends Base {
|
||||
id: data.interaction.id,
|
||||
type: InteractionTypes[data.interaction.type],
|
||||
commandName: data.interaction.name,
|
||||
user: this.client.users.add(data.interaction.user),
|
||||
user: this.client.users._add(data.interaction.user),
|
||||
};
|
||||
} else if (!this.interaction) {
|
||||
this.interaction = null;
|
||||
@@ -311,7 +311,7 @@ class Message extends Base {
|
||||
if ('content' in data) this.content = data.content;
|
||||
if ('pinned' in data) this.pinned = data.pinned;
|
||||
if ('tts' in data) this.tts = data.tts;
|
||||
if ('thread' in data) this.thread = this.client.channels.add(data.thread);
|
||||
if ('thread' in data) this.thread = this.client.channels._add(data.thread);
|
||||
|
||||
if ('attachments' in data) {
|
||||
this.attachments = new Collection();
|
||||
|
||||
@@ -18,7 +18,7 @@ class MessageComponentInteraction extends Interaction {
|
||||
* The message to which the component was attached
|
||||
* @type {Message|APIMessage}
|
||||
*/
|
||||
this.message = this.channel?.messages.add(data.message) ?? data.message;
|
||||
this.message = this.channel?.messages._add(data.message) ?? data.message;
|
||||
|
||||
/**
|
||||
* The custom id of the component which was interacted with
|
||||
|
||||
@@ -49,9 +49,9 @@ class MessageMentions {
|
||||
this.users = new Collection();
|
||||
for (const mention of users) {
|
||||
if (mention.member && message.guild) {
|
||||
message.guild.members.add(Object.assign(mention.member, { user: mention }));
|
||||
message.guild.members._add(Object.assign(mention.member, { user: mention }));
|
||||
}
|
||||
const user = message.client.users.add(mention);
|
||||
const user = message.client.users._add(mention);
|
||||
this.users.set(user.id, user);
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class MessageMentions {
|
||||
* The author of the message that this message is a reply to
|
||||
* @type {?User}
|
||||
*/
|
||||
this.repliedUser = repliedUser ? this.client.users.add(repliedUser) : null;
|
||||
this.repliedUser = repliedUser ? this.client.users._add(repliedUser) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ class TeamMember extends Base {
|
||||
* The user for this Team Member
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = this.client.users.add(data.user);
|
||||
this.user = this.client.users._add(data.user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ class TextChannel extends GuildChannel {
|
||||
}
|
||||
|
||||
if ('messages' in data) {
|
||||
for (const message of data.messages) this.messages.add(message);
|
||||
for (const message of data.messages) this.messages._add(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ class ThreadChannel extends Channel {
|
||||
}
|
||||
|
||||
if (data.member && this.client.user) this.members._add({ user_id: this.client.user.id, ...data.member });
|
||||
if (data.messages) for (const message of data.messages) this.messages.add(message);
|
||||
if (data.messages) for (const message of data.messages) this.messages._add(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -212,7 +212,7 @@ class User extends Base {
|
||||
recipient_id: this.id,
|
||||
},
|
||||
});
|
||||
return this.client.channels.add(data);
|
||||
return this.client.channels._add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,7 +223,7 @@ class User extends Base {
|
||||
const { dmChannel } = this;
|
||||
if (!dmChannel) throw new Error('USER_NO_DMCHANNEL');
|
||||
await this.client.api.channels(dmChannel.id).delete();
|
||||
this.client.channels.remove(dmChannel.id);
|
||||
this.client.channels._remove(dmChannel.id);
|
||||
return dmChannel;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,14 +70,14 @@ class Webhook {
|
||||
* The owner of the webhook
|
||||
* @type {?(User|APIUser)}
|
||||
*/
|
||||
this.owner = data.user ? this.client.users?.add(data.user) ?? data.user : null;
|
||||
this.owner = data.user ? this.client.users?._add(data.user) ?? data.user : null;
|
||||
|
||||
/**
|
||||
* The source guild of the webhook
|
||||
* @type {?(Guild|APIGuild)}
|
||||
*/
|
||||
this.sourceGuild = data.source_guild
|
||||
? this.client.guilds?.add(data.source_guild, false) ?? data.source_guild
|
||||
? this.client.guilds?._add(data.source_guild, false) ?? data.source_guild
|
||||
: null;
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ class Webhook {
|
||||
query: { thread_id: messagePayload.options.threadId, wait: true },
|
||||
auth: false,
|
||||
})
|
||||
.then(d => this.client.channels?.cache.get(d.channel_id)?.messages.add(d, false) ?? d);
|
||||
.then(d => this.client.channels?.cache.get(d.channel_id)?.messages._add(d, false) ?? d);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,7 +250,7 @@ class Webhook {
|
||||
if (!this.token) throw new Error('WEBHOOK_TOKEN_UNAVAILABLE');
|
||||
|
||||
const data = await this.client.api.webhooks(this.id, this.token).messages(message).get();
|
||||
return this.client.channels?.cache.get(data.channel_id)?.messages.add(data, cache) ?? data;
|
||||
return this.client.channels?.cache.get(data.channel_id)?.messages._add(data, cache) ?? data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +279,7 @@ class Webhook {
|
||||
if (!messageManager) return d;
|
||||
|
||||
const existing = messageManager.cache.get(d.id);
|
||||
if (!existing) return messageManager.add(d);
|
||||
if (!existing) return messageManager._add(d);
|
||||
|
||||
const clone = existing._clone();
|
||||
clone._patch(d);
|
||||
|
||||
Reference in New Issue
Block a user