From 124db01ae51f96cdb05ed959d3dcc85122631fd3 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 7 Apr 2023 13:06:50 +0100 Subject: [PATCH 1/2] feat(BaseInteraction): support new channel payload --- .../discord.js/src/structures/BaseInteraction.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/BaseInteraction.js b/packages/discord.js/src/structures/BaseInteraction.js index 3b6db688ef02..6cb47d4484d7 100644 --- a/packages/discord.js/src/structures/BaseInteraction.js +++ b/packages/discord.js/src/structures/BaseInteraction.js @@ -5,6 +5,7 @@ const { DiscordSnowflake } = require('@sapphire/snowflake'); const { InteractionType, ApplicationCommandType, ComponentType } = require('discord-api-types/v10'); const Base = require('./Base'); const { SelectMenuTypes } = require('../util/Constants'); +const Partials = require('../util/Partials'); const PermissionsBitField = require('../util/PermissionsBitField'); /** @@ -46,7 +47,18 @@ class BaseInteraction extends Base { * The id of the channel this interaction was sent in * @type {?Snowflake} */ - this.channelId = data.channel_id ?? null; + this.channelId = data.channel?.id ?? null; + + /** + * The channel this interaction was sent in. + * @type {?TextBasedChannels|APIChannel} + * @private + */ + this._channel = + (this.channelId && client.channels.cache.get(this.channelId)) ?? + client.options.partials.includes(Partials.Channel) + ? data.channel + : null; /** * The id of the guild this interaction was sent in @@ -159,7 +171,7 @@ class BaseInteraction extends Base { * @readonly */ get channel() { - return this.client.channels.cache.get(this.channelId) ?? null; + return this._channel; } /** From 8ead8285348ff1b8f2106d49066ce518816ddf8e Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:21:26 +0100 Subject: [PATCH 2/2] refactor(InteractionCreate): different approach Co-Authored-By: Synbulat Biishev --- .../src/client/actions/InteractionCreate.js | 2 +- .../discord.js/src/structures/BaseInteraction.js | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/discord.js/src/client/actions/InteractionCreate.js b/packages/discord.js/src/client/actions/InteractionCreate.js index c079121c7f6f..434fb0c0689c 100644 --- a/packages/discord.js/src/client/actions/InteractionCreate.js +++ b/packages/discord.js/src/client/actions/InteractionCreate.js @@ -20,7 +20,7 @@ class InteractionCreateAction extends Action { const client = this.client; // Resolve and cache partial channels for Interaction#channel getter - const channel = this.getChannel(data); + const channel = data.channel && this.getChannel(data.channel); // Do not emit this for interactions that cache messages that are non-text-based. let InteractionClass; diff --git a/packages/discord.js/src/structures/BaseInteraction.js b/packages/discord.js/src/structures/BaseInteraction.js index 6cb47d4484d7..967350fd0449 100644 --- a/packages/discord.js/src/structures/BaseInteraction.js +++ b/packages/discord.js/src/structures/BaseInteraction.js @@ -5,7 +5,6 @@ const { DiscordSnowflake } = require('@sapphire/snowflake'); const { InteractionType, ApplicationCommandType, ComponentType } = require('discord-api-types/v10'); const Base = require('./Base'); const { SelectMenuTypes } = require('../util/Constants'); -const Partials = require('../util/Partials'); const PermissionsBitField = require('../util/PermissionsBitField'); /** @@ -49,17 +48,6 @@ class BaseInteraction extends Base { */ this.channelId = data.channel?.id ?? null; - /** - * The channel this interaction was sent in. - * @type {?TextBasedChannels|APIChannel} - * @private - */ - this._channel = - (this.channelId && client.channels.cache.get(this.channelId)) ?? - client.options.partials.includes(Partials.Channel) - ? data.channel - : null; - /** * The id of the guild this interaction was sent in * @type {?Snowflake} @@ -171,7 +159,7 @@ class BaseInteraction extends Base { * @readonly */ get channel() { - return this._channel; + return this.client.channels.cache.get(this.channelId) ?? null; } /**