mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
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:
@@ -43,10 +43,27 @@ class Poll extends Base {
|
|||||||
|
|
||||||
Object.defineProperty(this, 'message', { value: message });
|
Object.defineProperty(this, 'message', { value: message });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The answers of this poll
|
||||||
|
* @type {Collection<number, PollAnswer|PartialPollAnswer>}
|
||||||
|
*/
|
||||||
|
this.answers = new Collection();
|
||||||
|
|
||||||
this._patch(data);
|
this._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
_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) {
|
if (data.results) {
|
||||||
/**
|
/**
|
||||||
* Whether this poll's results have been precisely counted
|
* Whether this poll's results have been precisely counted
|
||||||
@@ -111,23 +128,6 @@ class Poll extends Base {
|
|||||||
text: null,
|
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user