feat: PollBuilder (#10324)

* Add PollBuilder

* Add exports

* Update typings

* Update validations

* Use correct enum validator method

* Fix assertion, formatting

* Add tests

* Fix assertion

* Add JSDoc, format

* Make requested changes

* Remove unnecessary blank import

* Add support for PollBuilder in mainlib discord.js

* Add types, fix formatting

* Correct typings & assertions for poll answer emojis

* Improve typings readability

* Add JSDoc typings for overrides

* Add types for using PollBuilder in message payload

* Add tests, allow passing Emoji instance to emoji option

* Fix formatting

* Update max poll duration

* refactor: implement builders v2 pattern
This commit is contained in:
TÆMBØ
2025-02-28 02:07:27 -08:00
committed by GitHub
parent b6fda781c8
commit 88bfeaab22
10 changed files with 645 additions and 12 deletions

View File

@@ -192,17 +192,19 @@ class MessagePayload {
let poll;
if (this.options.poll) {
poll = {
question: {
text: this.options.poll.question.text,
},
answers: this.options.poll.answers.map(answer => ({
poll_media: { text: answer.text, emoji: resolvePartialEmoji(answer.emoji) },
})),
duration: this.options.poll.duration,
allow_multiselect: this.options.poll.allowMultiselect,
layout_type: this.options.poll.layoutType,
};
poll = isJSONEncodable(this.options.poll)
? this.options.poll.toJSON()
: {
question: {
text: this.options.poll.question.text,
},
answers: this.options.poll.answers.map(answer => ({
poll_media: { text: answer.text, emoji: resolvePartialEmoji(answer.emoji) },
})),
duration: this.options.poll.duration,
allow_multiselect: this.options.poll.allowMultiselect,
layout_type: this.options.poll.layoutType,
};
}
this.body = {

View File

@@ -176,6 +176,7 @@ import {
RESTAPIInteractionCallbackActivityInstanceResource,
VoiceChannelEffectSendAnimationType,
GatewayVoiceChannelEffectSendDispatchData,
RESTAPIPoll,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { Stream } from 'node:stream';
@@ -6352,7 +6353,7 @@ export interface BaseMessageOptions {
}
export interface BaseMessageOptionsWithPoll extends BaseMessageOptions {
poll?: PollData;
poll?: JSONEncodable<RESTAPIPoll> | PollData;
}
export interface MessageCreateOptions extends BaseMessageOptionsWithPoll {