Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove fromInteraction in internal channel creation #9335

Merged
merged 3 commits into from Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/discord.js/src/managers/ChannelManager.js
Expand Up @@ -36,18 +36,18 @@ class ChannelManager extends CachedManager {
* @name ChannelManager#cache
*/

_add(data, guild, { cache = true, allowUnknownGuild = false, fromInteraction = false } = {}) {
_add(data, guild, { cache = true, allowUnknownGuild = false } = {}) {
const existing = this.cache.get(data.id);
if (existing) {
if (cache) existing._patch(data, fromInteraction);
if (cache) existing._patch(data);
guild?.channels?._add(existing);
if (ThreadChannelTypes.includes(existing.type)) {
existing.parent?.threads?._add(existing);
}
return existing;
}

const channel = createChannel(this.client, data, guild, { allowUnknownGuild, fromInteraction });
const channel = createChannel(this.client, data, guild, { allowUnknownGuild });

if (!channel) {
this.client.emit(Events.Debug, `Failed to find guild, or unknown type for channel ${data.id} ${data.type}`);
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/structures/ThreadChannel.js
Expand Up @@ -14,7 +14,7 @@ const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
* @implements {TextBasedChannel}
*/
class ThreadChannel extends BaseChannel {
constructor(guild, data, client, fromInteraction = false) {
constructor(guild, data, client) {
super(guild?.client ?? client, data, false);

/**
Expand All @@ -40,10 +40,10 @@ class ThreadChannel extends BaseChannel {
* @type {ThreadMemberManager}
*/
this.members = new ThreadMemberManager(this);
if (data) this._patch(data, fromInteraction);
if (data) this._patch(data);
}

_patch(data, partial = false) {
_patch(data) {
super._patch(data);

if ('message' in data) this.messages._add(data.message);
Expand Down Expand Up @@ -149,7 +149,7 @@ class ThreadChannel extends BaseChannel {
this.lastPinTimestamp ??= null;
}

if ('rate_limit_per_user' in data || !partial) {
if ('rate_limit_per_user' in data) {
/**
* The rate limit per user (slowmode) for this thread in seconds
* @type {?number}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/util/Channels.js
Expand Up @@ -23,7 +23,7 @@ const getForumChannel = lazy(() => require('../structures/ForumChannel'));
* @returns {Channel} Any kind of channel.
* @ignore
*/
function createChannel(client, data, guild, { allowUnknownGuild, fromInteraction } = {}) {
function createChannel(client, data, guild, { allowUnknownGuild } = {}) {
let channel;
if (!data.guild_id && !guild) {
if ((data.recipients && data.type !== ChannelType.GroupDM) || data.type === ChannelType.DM) {
Expand Down Expand Up @@ -59,7 +59,7 @@ function createChannel(client, data, guild, { allowUnknownGuild, fromInteraction
case ChannelType.AnnouncementThread:
case ChannelType.PublicThread:
case ChannelType.PrivateThread: {
channel = new (getThreadChannel())(guild, data, client, fromInteraction);
channel = new (getThreadChannel())(guild, data, client);
if (!allowUnknownGuild) channel.parent?.threads.cache.set(channel.id, channel);
break;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -2944,7 +2944,7 @@ export class ThreadChannel<Forum extends boolean = boolean> extends TextBasedCha
'createWebhook',
'setNSFW',
]) {
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>, fromInteraction?: boolean);
private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client<true>);
public archived: boolean | null;
public get archivedAt(): Date | null;
public archiveTimestamp: number | null;
Expand Down Expand Up @@ -3138,7 +3138,6 @@ export interface MappedComponentTypes {

export interface ChannelCreateOptions {
allowFromUnknownGuild?: boolean;
fromInteraction?: boolean;
}

export function createChannel(client: Client<true>, data: APIChannel, options?: ChannelCreateOptions): Channel;
Expand Down