fix(Poll): ensure this.answers is set before we reference it (#10809)

* Ensure 	his.answers is set sooner if it's null during a patch

* Move data.answers block up as well to ensure the patched answers are set

* Ensure collection is set in constructor instead

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jacob Morrison
2025-03-27 14:01:05 -04:00
committed by GitHub
parent 73f2ef9c87
commit 3234fc6b3b

View File

@@ -43,10 +43,27 @@ class Poll extends Base {
Object.defineProperty(this, 'message', { value: message });
/**
* The answers of this poll
* @type {Collection<number, PollAnswer|PartialPollAnswer>}
*/
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);
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
@@ -111,23 +128,6 @@ class Poll extends Base {
text: null,
};
}
/**
* The answers of this poll
* @type {Collection<number, PollAnswer|PartialPollAnswer>}
*/
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));
}
}
}
}
/**