mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 02:23:31 +01:00
fix(ThreadChannel): better property handling (#6172)
This commit is contained in:
@@ -19,10 +19,10 @@ class ChannelManager extends CachedManager {
|
||||
* @name ChannelManager#cache
|
||||
*/
|
||||
|
||||
_add(data, guild, cache = true, allowUnknownGuild = false) {
|
||||
_add(data, guild, { cache = true, allowUnknownGuild = false, fromInteraction = false } = {}) {
|
||||
const existing = this.cache.get(data.id);
|
||||
if (existing) {
|
||||
if (cache) existing._patch(data);
|
||||
if (cache) existing._patch(data, fromInteraction);
|
||||
guild?.channels?._add(existing);
|
||||
if (ThreadChannelTypes.includes(existing.type)) {
|
||||
existing.parent?.threads?._add(existing);
|
||||
@@ -30,7 +30,7 @@ class ChannelManager extends CachedManager {
|
||||
return existing;
|
||||
}
|
||||
|
||||
const channel = Channel.create(this.client, data, guild, allowUnknownGuild);
|
||||
const channel = Channel.create(this.client, data, guild, { allowUnknownGuild, fromInteraction });
|
||||
|
||||
if (!channel) {
|
||||
this.client.emit(Events.DEBUG, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
|
||||
@@ -99,7 +99,7 @@ class ChannelManager extends CachedManager {
|
||||
}
|
||||
|
||||
const data = await this.client.api.channels(id).get();
|
||||
return this._add(data, null, cache, allowUnknownGuild);
|
||||
return this._add(data, null, { cache, allowUnknownGuild });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,12 +169,12 @@ class GuildChannelManager extends CachedManager {
|
||||
const data = await this.client.api.channels(id).get();
|
||||
// Since this is the guild manager, throw if on a different guild
|
||||
if (this.guild.id !== data.guild_id) throw new Error('GUILD_CHANNEL_UNOWNED');
|
||||
return this.client.channels._add(data, this.guild, cache);
|
||||
return this.client.channels._add(data, this.guild, { cache });
|
||||
}
|
||||
|
||||
const data = await this.client.api.guilds(this.guild.id).channels.get();
|
||||
const channels = new Collection();
|
||||
for (const channel of data) channels.set(channel.id, this.client.channels._add(channel, this.guild, cache));
|
||||
for (const channel of data) channels.set(channel.id, this.client.channels._add(channel, this.guild, { cache }));
|
||||
return channels;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ class ThreadManager extends CachedManager {
|
||||
|
||||
_mapThreads(rawThreads, cache) {
|
||||
const threads = rawThreads.threads.reduce((coll, raw) => {
|
||||
const thread = this.client.channels._add(raw, null, cache);
|
||||
const thread = this.client.channels._add(raw, null, { cache });
|
||||
return coll.set(thread.id, thread);
|
||||
}, new Collection());
|
||||
// Discord sends the thread id as id in this object
|
||||
|
||||
Reference in New Issue
Block a user