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
This commit is contained in:
Jiralite
2022-04-12 16:12:31 +01:00
committed by GitHub
parent a1329bd3eb
commit 25fdb3894d

View File

@@ -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;