From 925583f82c7849ad10029d08b3ac115ce91ceee6 Mon Sep 17 00:00:00 2001 From: Qjuh <76154676+Qjuh@users.noreply.github.com> Date: Sat, 14 Sep 2024 12:22:59 +0200 Subject: [PATCH 1/2] fix: `GuildChannel#guildId` not being patched to `undefined` --- packages/discord.js/src/client/actions/MessageCreate.js | 6 +++++- packages/discord.js/src/client/actions/MessageDelete.js | 2 +- .../discord.js/src/client/actions/MessagePollVoteAdd.js | 2 +- .../discord.js/src/client/actions/MessagePollVoteRemove.js | 2 +- .../discord.js/src/client/actions/MessageReactionAdd.js | 2 +- .../discord.js/src/client/actions/MessageReactionRemove.js | 6 +++++- .../src/client/actions/MessageReactionRemoveAll.js | 2 +- .../src/client/actions/MessageReactionRemoveEmoji.js | 2 +- packages/discord.js/src/client/actions/MessageUpdate.js | 2 +- packages/discord.js/src/client/actions/TypingStart.js | 2 +- 10 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/discord.js/src/client/actions/MessageCreate.js b/packages/discord.js/src/client/actions/MessageCreate.js index 2babdaf3b287..393cdfe54c5c 100644 --- a/packages/discord.js/src/client/actions/MessageCreate.js +++ b/packages/discord.js/src/client/actions/MessageCreate.js @@ -6,7 +6,11 @@ const Events = require('../../util/Events'); class MessageCreateAction extends Action { handle(data) { const client = this.client; - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id, author: data.author }); + const channel = this.getChannel({ + id: data.channel_id, + author: data.author, + ...(data.guildId && { guild_id: data.guild_id }), + }); if (channel) { if (!channel.isTextBased()) return {}; diff --git a/packages/discord.js/src/client/actions/MessageDelete.js b/packages/discord.js/src/client/actions/MessageDelete.js index 34acb42b3ba4..c67c5abf0ecf 100644 --- a/packages/discord.js/src/client/actions/MessageDelete.js +++ b/packages/discord.js/src/client/actions/MessageDelete.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class MessageDeleteAction extends Action { handle(data) { const client = this.client; - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, ...('guild_id' in data && { guild_id: data.guild_id }) }); let message; if (channel) { if (!channel.isTextBased()) return {}; diff --git a/packages/discord.js/src/client/actions/MessagePollVoteAdd.js b/packages/discord.js/src/client/actions/MessagePollVoteAdd.js index 2a2bdc649ee1..411467ca3d1f 100644 --- a/packages/discord.js/src/client/actions/MessagePollVoteAdd.js +++ b/packages/discord.js/src/client/actions/MessagePollVoteAdd.js @@ -5,7 +5,7 @@ const Events = require('../../util/Events'); class MessagePollVoteAddAction extends Action { handle(data) { - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, ...('guild_id' in data && { guild_id: data.guild_id }) }); if (!channel?.isTextBased()) return false; const message = this.getMessage(data, channel); diff --git a/packages/discord.js/src/client/actions/MessagePollVoteRemove.js b/packages/discord.js/src/client/actions/MessagePollVoteRemove.js index c3eab3bd6742..afae556a4b94 100644 --- a/packages/discord.js/src/client/actions/MessagePollVoteRemove.js +++ b/packages/discord.js/src/client/actions/MessagePollVoteRemove.js @@ -5,7 +5,7 @@ const Events = require('../../util/Events'); class MessagePollVoteRemoveAction extends Action { handle(data) { - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, ...('guild_id' in data && { guild_id: data.guild_id }) }); if (!channel?.isTextBased()) return false; const message = this.getMessage(data, channel); diff --git a/packages/discord.js/src/client/actions/MessageReactionAdd.js b/packages/discord.js/src/client/actions/MessageReactionAdd.js index b32f7154f102..de026a82bb73 100644 --- a/packages/discord.js/src/client/actions/MessageReactionAdd.js +++ b/packages/discord.js/src/client/actions/MessageReactionAdd.js @@ -25,7 +25,7 @@ class MessageReactionAdd extends Action { // Verify channel const channel = this.getChannel({ id: data.channel_id, - guild_id: data.guild_id, + ...('guild_id' in data && { guild_id: data.guild_id }), user_id: data.user_id, ...this.spreadInjectedData(data), }); diff --git a/packages/discord.js/src/client/actions/MessageReactionRemove.js b/packages/discord.js/src/client/actions/MessageReactionRemove.js index 5430a37c461e..888f354f110a 100644 --- a/packages/discord.js/src/client/actions/MessageReactionRemove.js +++ b/packages/discord.js/src/client/actions/MessageReactionRemove.js @@ -19,7 +19,11 @@ class MessageReactionRemove extends Action { if (!user) return false; // Verify channel - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id, user_id: data.user_id }); + const channel = this.getChannel({ + id: data.channel_id, + ...('guild_id' in data && { guild_id: data.guild_id }), + user_id: data.user_id, + }); if (!channel?.isTextBased()) return false; // Verify message diff --git a/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js b/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js index 5816341732f6..df3d5001cb6c 100644 --- a/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js +++ b/packages/discord.js/src/client/actions/MessageReactionRemoveAll.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class MessageReactionRemoveAll extends Action { handle(data) { // Verify channel - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, ...('guild_id' in data && { guild_id: data.guild_id }) }); if (!channel?.isTextBased()) return false; // Verify message diff --git a/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js b/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js index 2916f061d290..4f8706317ee6 100644 --- a/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js +++ b/packages/discord.js/src/client/actions/MessageReactionRemoveEmoji.js @@ -5,7 +5,7 @@ const Events = require('../../util/Events'); class MessageReactionRemoveEmoji extends Action { handle(data) { - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, ...('guild_id' in data && { guild_id: data.guild_id }) }); if (!channel?.isTextBased()) return false; const message = this.getMessage(data, channel); diff --git a/packages/discord.js/src/client/actions/MessageUpdate.js b/packages/discord.js/src/client/actions/MessageUpdate.js index 181c17448c75..4aa4f84def5c 100644 --- a/packages/discord.js/src/client/actions/MessageUpdate.js +++ b/packages/discord.js/src/client/actions/MessageUpdate.js @@ -4,7 +4,7 @@ const Action = require('./Action'); class MessageUpdateAction extends Action { handle(data) { - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, ...('guild_id' in data && { guild_id: data.guild_id }) }); if (channel) { if (!channel.isTextBased()) return {}; diff --git a/packages/discord.js/src/client/actions/TypingStart.js b/packages/discord.js/src/client/actions/TypingStart.js index 8e217eccc909..637edaa3e960 100644 --- a/packages/discord.js/src/client/actions/TypingStart.js +++ b/packages/discord.js/src/client/actions/TypingStart.js @@ -6,7 +6,7 @@ const Events = require('../../util/Events'); class TypingStart extends Action { handle(data) { - const channel = this.getChannel({ id: data.channel_id, guild_id: data.guild_id }); + const channel = this.getChannel({ id: data.channel_id, ...('guild_id' in data && { guild_id: data.guild_id }) }); if (!channel) return; if (!channel.isTextBased()) { From 20fb40bdabb9d17c4a13f575b12c6e904bca0d06 Mon Sep 17 00:00:00 2001 From: Qjuh <76154676+Qjuh@users.noreply.github.com> Date: Sat, 14 Sep 2024 12:55:21 +0200 Subject: [PATCH 2/2] fix: guildId to guild_id check --- packages/discord.js/src/client/actions/MessageCreate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/client/actions/MessageCreate.js b/packages/discord.js/src/client/actions/MessageCreate.js index 393cdfe54c5c..cba5ab7bf0e0 100644 --- a/packages/discord.js/src/client/actions/MessageCreate.js +++ b/packages/discord.js/src/client/actions/MessageCreate.js @@ -9,7 +9,7 @@ class MessageCreateAction extends Action { const channel = this.getChannel({ id: data.channel_id, author: data.author, - ...(data.guildId && { guild_id: data.guild_id }), + ...('guild_id' in data && { guild_id: data.guild_id }), }); if (channel) { if (!channel.isTextBased()) return {};