From 01b39be409b86749b520dabc485766e7a47933ab Mon Sep 17 00:00:00 2001 From: Jake Morrison Date: Wed, 19 Mar 2025 13:14:57 -0400 Subject: [PATCH 1/3] Ensure his.answers is set sooner if it's null during a patch --- packages/discord.js/src/structures/Poll.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/discord.js/src/structures/Poll.js b/packages/discord.js/src/structures/Poll.js index 3fd0630e48a6..2694ff5dc0e4 100644 --- a/packages/discord.js/src/structures/Poll.js +++ b/packages/discord.js/src/structures/Poll.js @@ -47,6 +47,12 @@ class Poll extends Base { } _patch(data) { + /** + * The answers of this poll + * @type {Collection} + */ + this.answers ??= new Collection(); + if (data.results) { /** * Whether this poll's results have been precisely counted @@ -112,12 +118,6 @@ class Poll extends Base { }; } - /** - * The answers of this poll - * @type {Collection} - */ - this.answers ??= new Collection(); - if (data.answers) { for (const answer of data.answers) { const existing = this.answers.get(answer.answer_id); From 5f080ab75ec6808284b750f707d9c2c3e7494de6 Mon Sep 17 00:00:00 2001 From: Jake Morrison Date: Wed, 19 Mar 2025 13:28:25 -0400 Subject: [PATCH 2/3] Move data.answers block up as well to ensure the patched answers are set --- packages/discord.js/src/structures/Poll.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/discord.js/src/structures/Poll.js b/packages/discord.js/src/structures/Poll.js index 2694ff5dc0e4..d856e0f15a6d 100644 --- a/packages/discord.js/src/structures/Poll.js +++ b/packages/discord.js/src/structures/Poll.js @@ -53,6 +53,17 @@ class Poll extends Base { */ this.answers ??= new Collection(); + if (data.answers) { + for (const answer of data.answers) { + const existing = this.answers.get(answer.answer_id); + if (existing) { + existing._patch(answer); + } else { + this.answers.set(answer.answer_id, new PollAnswer(this.client, answer, this)); + } + } + } + if (data.results) { /** * Whether this poll's results have been precisely counted @@ -117,17 +128,6 @@ class Poll extends Base { text: null, }; } - - if (data.answers) { - for (const answer of data.answers) { - const existing = this.answers.get(answer.answer_id); - if (existing) { - existing._patch(answer); - } else { - this.answers.set(answer.answer_id, new PollAnswer(this.client, answer, this)); - } - } - } } /** From a93795b0378ca0be075b38c8b4430e07d92276b3 Mon Sep 17 00:00:00 2001 From: Jake Morrison Date: Wed, 19 Mar 2025 15:37:51 -0400 Subject: [PATCH 3/3] Ensure collection is set in constructor instead --- packages/discord.js/src/structures/Poll.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/discord.js/src/structures/Poll.js b/packages/discord.js/src/structures/Poll.js index d856e0f15a6d..202c94ade2be 100644 --- a/packages/discord.js/src/structures/Poll.js +++ b/packages/discord.js/src/structures/Poll.js @@ -43,16 +43,16 @@ class Poll extends Base { Object.defineProperty(this, 'message', { value: message }); - this._patch(data); - } - - _patch(data) { /** * The answers of this poll * @type {Collection} */ - this.answers ??= new Collection(); + this.answers = new Collection(); + this._patch(data); + } + + _patch(data) { if (data.answers) { for (const answer of data.answers) { const existing = this.answers.get(answer.answer_id);