From 25fdb3894d33dc395a376a3d962a063eb5735253 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Apr 2022 16:12:31 +0100 Subject: [PATCH] fix(InteractionCreateAction): Ensure text-based channel for caching messages (#7755) * fix: ensure text-based channel for adding messages * fix: account for interaction-only applications The event will emit for these types of bots. However, as the channel is not from a cached guild, they are safe from this crash. * fix: typos * refactor: more descriptive variable usage --- .../discord.js/src/client/actions/InteractionCreate.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/discord.js/src/client/actions/InteractionCreate.js b/packages/discord.js/src/client/actions/InteractionCreate.js index 5ec2b8fb2..a26478142 100644 --- a/packages/discord.js/src/client/actions/InteractionCreate.js +++ b/packages/discord.js/src/client/actions/InteractionCreate.js @@ -16,9 +16,11 @@ class InteractionCreateAction extends Action { const client = this.client; // Resolve and cache partial channels for Interaction#channel getter - this.getChannel(data); + const channel = this.getChannel(data); + // Do not emit this for interactions that cache messages that are non-text-based. let InteractionClass; + switch (data.type) { case InteractionType.ApplicationCommand: switch (data.data.type) { @@ -29,6 +31,7 @@ class InteractionCreateAction extends Action { InteractionClass = UserContextMenuCommandInteraction; break; case ApplicationCommandType.Message: + if (channel && !channel.isTextBased()) return; InteractionClass = MessageContextMenuCommandInteraction; break; default: @@ -40,6 +43,8 @@ class InteractionCreateAction extends Action { } break; case InteractionType.MessageComponent: + if (channel && !channel.isTextBased()) return; + switch (data.data.component_type) { case ComponentType.Button: InteractionClass = ButtonInteraction;