class PollBuilder

export declare class PollBuilder implements JSONEncodable<RESTAPIPoll>

A builder that creates API-compatible JSON data for polls.

Constructors

constructor()

Creates a new poll from API data.

readonly
answers : readonly PollAnswerBuilder[]

Gets the answers of this poll.

addAnswers() : this

Appends answers to the poll.

Examples:Using an array:
const answers: APIPollMedia[] = ...;
const poll = new PollBuilder()
	.addAnswers(answers);
Using rest parameters (variadic):
const poll = new PollBuilder()
	.addAnswers(
		{ text: 'Answer 1' },
		{ text: 'Answer 2' },
	);

clearDuration() : this

Clears the duration for this poll.

clearLayoutType() : this

Clears the layout type for this poll.

setAnswers() : this

Sets the answers for this poll.

setDuration(
duration: number
) : this

Sets how long this poll will be open for in hours.

setLayoutType() : this

Sets the layout type for this poll.

setMultiSelect(
multiSelect?: boolean
) : this

Sets whether multi-select is enabled for this poll.

setQuestion() : this

Sets the question for this poll.

spliceAnswers(
index: number
deleteCount: number
...answers: (Omit<APIPollAnswer, 'answer_id'> | PollAnswerBuilder | ((builder: PollAnswerBuilder) => PollAnswerBuilder))[]
) : this

Removes, replaces, or inserts answers for this poll.

Examples:Remove the first answer:
poll.spliceAnswers(0, 1);
Remove the first n answers:
const n = 4;
poll.spliceAnswers(0, n);
Remove the last answer:
poll.spliceAnswers(-1, 1);

toJSON(
validationOverride?: boolean
) : RESTAPIPoll

Serializes this builder to API-compatible JSON data.Note that by disabling validation, there is no guarantee that the resulting object will be valid.

updateQuestion(
updater: (builder: PollQuestionBuilder) => void
) : this

Updates the question of this poll.