mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
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:
@@ -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 = {
|
||||
|
||||
3
packages/discord.js/typings/index.d.ts
vendored
3
packages/discord.js/typings/index.d.ts
vendored
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user